Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:37:05+00:00 2026-05-28T05:37:05+00:00

I have one WPF ListBox loaded using LINQ: lbxCalculosSec.ItemsSource = from p in database.CALCULOS

  • 0

I have one WPF ListBox loaded using LINQ:

lbxCalculosSec.ItemsSource = from p in database.CALCULOS
                             orderby p.NOMBRECALCULO
                             select new { ID = p.IDCALCULO, NOMBRE = p.NOMBRECALCULO + " - " + p.DESCRIPCIONCALCULO };

lbxCalculosSec.DisplayMemberPath = "NOMBRE";
lbxCalculosSec.SelectedValuePath = "ID";

The listbox has multiselect = true. The problem is when I try to retrieve all the SelectedValue’s (ID’s) from SelectedItems List.

When I inspect one SelectedItem at runtime, the object type is “<>f__AnonymousType0`2”

I tried using this:

ItemPropertyInfo ID  = null;

lbxCalculosSec.SelectedItem.GetType().GetProperty("ID").GetValue(ID as ItemPropertyInfo, null)

But it didn’t work.

I need a solution to access ListBox Selected Values (ID fields).

Thank you very much in advance.

Kind Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:37:06+00:00Added an answer on May 28, 2026 at 5:37 am

    GetValue expects the instance on which the property is defined, in this case it’s the SelectedItem:

    var item = lbxCalculosSec.SelectedItem;
    ItemPropertyInfo ID  = (ItemPropertyInfo)item.GetType()
                                                 .GetProperty("ID")
                                                 .GetValue(item, null);
    

    Edit
    If ID is of some other type, like int, the code should be:

    var item = lbxCalculosSec.SelectedItem;
    int ID  = (int)item.GetType()
                       .GetProperty("ID")
                       .GetValue(item, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an observable collection bound to a listbox in WPF. One of the
I have this line in WPF (.NET 3.5) : <ListBox ItemsSource={Binding Locks} Style={DynamicResource FancyListBox}
My WPF Listbox should have two columns. The one on the right should have
I have WPF Application where I have One main form and other user controls
This relates to Composite Application Guidance for WPF, or Prism. I have one MainRegion
When doing databinding does one have to implement INotifyPropertyChanged on the datacontext in WPF?
This one has me beat; I have a WPF window with two (important for
I have one website on my server, and my IIS Worker Process is using
I have a WPF Listbox filled with children that fire events. Now, I am
I have a WPF listbox control that is declaratively bound to a textbox. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.