1

I have a strange problem with a listbox. I added only the listbox and a button which adds items to the listbox. If I click an item in the listbox it seems to have some strange multi selection mode on or something... i recorded a short screen cast, see for your self:

http://www.youtube.com/watch?v=zV4424ipNEA
any ideas whats wrong?

4
  • Do you hold Ctrl button pressed? :) Commented Sep 1, 2011 at 15:18
  • nope.. but i will reboot and check, maybe something hangs... Commented Sep 1, 2011 at 15:21
  • I rebooted without luck.. it's really a strange problem :( Commented Sep 1, 2011 at 15:34
  • This should show some code Commented Apr 30, 2020 at 20:21

1 Answer 1

4

That is a known issue, as all those strings are the same the selection gets confused because they all are essentially the same object. If you create two identical strings in .NET it does not necessarily create a new one but may reuse the first instance, i am not an expert on this though.

Either wrap the strings in a class (make them the Content of a ListBoxItem for example) or make sure the values are unique.

Sign up to request clarification or add additional context in comments.

3 Comments

you are my hero :) the list box will of course have different items.
Glad that helped! You can give heroes upvotes by the way, not that i'd want any :D
Having tried this initially without success, I have to flag a comment by @Oliver Hanappi in a similar thread which states that you cannot have Equals/GetHashCode overrides on your wrapper class that implement value equality, which I was, and now am not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.