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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:20:21+00:00 2026-06-07T05:20:21+00:00

I have a ListBox that contains duplicate items. From what I gather, ListBox.SelectedItems will

  • 0

I have a ListBox that contains duplicate items. From what I gather, ListBox.SelectedItems will only return the first instance of a duplicate, but this causes problems when I want to perform an action on all items a user has selected. When I select multiple duplicates and call ListBox.SelectedItems.Count, I always get 1. Is there a way to get the indexes of all items, regardless if they’re unique or not? (ListBox mode is set to Multiple).

Added repro code demonstrating that the same item is considered a duplicate.

Xaml:

<Grid x:Name="LayoutRoot" Background="White">
   <ListBox Height="288" HorizontalAlignment="Left" Margin="12,0,0,0" Name="listBox1" VerticalAlignment="Top" Width="276" SelectionMode="Multiple" />
   <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="313,12,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>

code:

ObservableCollection<string> fruits = new ObservableCollection<string>();
fruits.Add("Apple");
fruits.Add("Pear");
fruits.Add("Orange");
fruits.Add("Apple");
listBox1.ItemsSource = fruits ;

I just wired up a button event to this:

MessageBox.Show(listBox1.SelectedItems.Count.ToString());

Select the top Apple and click the button, it will return 1. Select both Apples and it will return 1. Select an Apple and Pear, it will return 2.

  • 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-07T05:20:23+00:00Added an answer on June 7, 2026 at 5:20 am

    I’ve added a GUID property in my class and randomised it before adding to the ObservableCollection. User doesn’t see the GUID, but the ListBoxItem is still considered unique and it now works. I’ll leave this question open for a bit incase someone knows of a solution that doesn’t require modifying the class unnecessarily.

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

Sidebar

Related Questions

I have a ListBox control, that contains a few items that display attachments (files
I have a ListBox that contains a number of User items that are DataTemplate
I have a ListBox that contains a System.net.IPAddress and string items. I want to
I have a wpf listbox that implements a DataTemplate that contains a TextBlock. <local:BooleanToFontColorConverter
I have a listbox item template that contains visual states. I have DisplayStateBehaviors that
I have a ListBox with ListBoxItem s that contains a nested ListBox . Now
I have a list box control that contains enough items to list them with
I have a listbox that displays Shipment Items (custom class) that are formatted using
I have a listbox that has a datatemplate which contains multiple text boxes. I
I have a PivotControl that contains ListBox elements: <controls:Pivot Title=SECTIONS x:Name=pivotControl ItemsSource={Binding SectionViewModels}> <controls:Pivot.HeaderTemplate>

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.