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

  • Home
  • SEARCH
  • 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 6017205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:05:42+00:00 2026-05-23T03:05:42+00:00

A ListView (or ListBox) with following properties: <ListView SelectionMode=Single> <sys:String>James</sys:String> <sys:String>Claude</sys:String> <sys:String>Justing</sys:String> <sys:String>James</sys:String> </ListView>

  • 0

A ListView (or ListBox) with following properties:

  <ListView SelectionMode="Single">
     <sys:String>James</sys:String>
     <sys:String>Claude</sys:String>
     <sys:String>Justing</sys:String>
     <sys:String>James</sys:String>
  </ListView>

will result in selecting two items simultaneously if I click on “James”, even though
I chose SelectionMode=”Single”. It’s even the same behaviour when I use a helper class with
a string-property to display in the ListView. It seems like the ListView is evaluating the Items and selecting those which are Equal() rather than ReferenceEqual(). Is there a way to change this behaviour so that the ListView treats every item individually?

  • 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-23T03:05:43+00:00Added an answer on May 23, 2026 at 3:05 am

    The problem really is Equals() versus ReferenceEquals().

    It’s even the same behaviour when I use a helper class with a string-property to display in the ListView.

    Not quite. You get the same behavior if you use an anonymous helper class.

    Why doesn’t wrapping an anonymous type around the string fix the problem? As described here, when you create an anonymous type, the compiler creates a generic Equals() method that returns true if the objects are of the same (anonymous) type and their properties have the same values.

    The solution is to implement a real (non-anonymous) class – it can be as simple as this:

    public class Item
    {
        public string Display { get; set; }
    }
    

    Object.Equals() does a reference comparison, so as long as you don’t override it, you’ll get the behavior you would expect.

    I suspect that the design of the control assumes that you’re not going using it to display lists containing two equal items.

    As to why it uses Equals and not ReferenceEquals, I suspect that the underlying design choice has to do with the fact that controls have to be able to display value types. ReferenceEquals boxes value types, with the result that ReferenceEquals(1,1) returns false.

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

Sidebar

Related Questions

Been trying to find a working implementation of a WPF listview (or listbox) where
I'm considering either a ListBox or a ListView for a WPF application. It seems
I have a databound listbox which is actually displaying two columns of data. It
When I use the following code it works because I am using a ListBox
I've seen a lot of code for doing listbox or listview thumbnails with hard
I've been trying for a while to display some data in a listbox/listview that
EDIT: It is not a listbox. My mistake. It is a list view. I
I have a ListView control, and I'm trying to figure out the easiest/best way
I have a ListView which sometimes I need to put around 10000 items in.
So I have a ListView with an upper limit of about 1000 items. I

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.