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 8629433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:48:18+00:00 2026-06-12T08:48:18+00:00

My WPF application has a ListBox in it. The ListBox’s ItemsSource property is set

  • 0

My WPF application has a ListBox in it. The ListBox's ItemsSource property is set to a collection of objects I have defined. These all descend from UserControl.

I need to loop over the items in the ListBox in the order that they appear on screen. I believe I can do this by looping over the ListBox's Items collection.

I believe that the objects inthis collection are of type ListBoxItem. How do I get at the objects of my type from the ListBoxItem? In other words, how do I get at the instance of my class descended from UserControl from the ListBoxItem?

EDIT:

Additional information I should have included in the first place:

I need to loop over the Items in the order that they appear in the ListBox so I can select the one closest to the top that matches a particular condition. After I find the one I’m interested in, I need to select it. It’s a single select ListBox, so only one item at a time will be selected.

So, my question really is: How do I select the Item?

Not that it matters, but the reason my type descends from UserControl is because it contains a number of controls that need to be diplayed in the ListBox for each item.

  • 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-06-12T08:48:19+00:00Added an answer on June 12, 2026 at 8:48 am

    I found that I needed to loop over the items in the Items collection in reverse order. I’m not sure why this is, I thought that the Items collection held everything in the order they appear on screen. Perhaps it’s because the ListBox is sorted in descending order on a DateTime property of the underlying data?

    In any case, since I had to loop backwards, I ended up having to write a for loop that started at the end of the collection and worked its way forwards. Since I now had the index of the item I wanted to select, it was easy to just set ListBox.SelectedIndex to that index.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGrid in a WPF application which has for its ItemsSource a
I have a wpf application using caliburn.micro. It has a datagrid and a combobox.
I have a WPF application with ListBox that display list of items. Each item
I have a WPF application which so far has been client only, but now
I have a small WPF application. This application has a button that when clicked,
In WPF, MVVC applicaiton I have quite normal listbox: <ListBox ItemsSource={Binding Friends}> </ListBox> Then
I have a WPF application that has a list box of images. Right now
My WPF application has a DataGrid control in it. I have a default custom
I have an application where you can select between different objects in a ListBox.
I have a wpf application that has a button for for each folder under

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.