ComboBox’s SelectedItem not Displaying

I see a lot of posts on StackOverflow about WPF ComboBoxes not displaying the SelectedItem correctly.

The code given usually looks something like this:

<ComboBox ItemsSource="{Binding MyList}"
          SelectedItem="{Binding MyItem}" />

The problem is simple: By default WPF compares SelectedItem to each item in the ItemsSource by reference, meaning that unless the SelectedItem points to the same item in memory as the ItemsSource item, it will decide that the item doesn’t exist in the ItemsSource and so no item gets selected.

To work around this, you can either use the ComboBox’s SelectedValue and SelectedValuePath to set the SelectedItem by Value instead of by Item

<ComboBox ItemsSource="{Binding MyList}"
          SelectedValue="{Binding SelectedId}" />

Or you can overwrite the .Equals() method of the MyItem class so that it returns true if two item’s have the same data, not just the same memory reference.

public override bool Equals(object obj) 
    if (obj == null || !(obj is MyClass)) 
        return false; 
    return ((MyClass)obj).Id == this.Id); 

22 Responses to ComboBox’s SelectedItem not Displaying

  1. Oli says:

    Very helpful, thanks !
    However I also had to override the GetHashCode method.

  2. Arpit Singh says:

    Thank you. I always struggled with my Comboboxes. This helped.

  3. Sauso says:

    Thank you for this post! I spent 2 days looking for this clear explanation!

  4. Alon says:

    Thanks! Helped me a lot!

  5. Martin Fontán says:

    it seems that this helps for many years and it has helped me today. it is in a way logical but annoying behavior

  6. SaravanaSanthosh says:

    you are awesome!!! this helped me:)

  7. Thank you!! this post helped me.

  8. Thank you so much! I’ve been looking at my project for two hours and your post eventually helped me out!

  9. Oliver Fehr says:

    Overriding Equals() was the solution for me! Thanks!

  10. Matias says:

    This post saved mi life, I searched everywhere and you describe my problem just as it is. Thanks a lot Rachel. You are fantastic.

  11. Rajib says:

    Hi Rachel,
    I am trying to fix someone else’s code that suffers from this bug. The combo box is not populating with the selected item. I have overridden the Equals method in my item class, but that does not solve the problem. I’ve pasted some code below. Any insight that you can provide is highly appreciated.

    — Here is the code for the equals method
    public override bool Equals(object obj)
    if (obj == null || !(obj is Dose))
    return false;

    return ((Dose)obj).Id == this.Id;

    • Rachel says:

      Hi Rajib, try posting a question on with the relevant XAML and code-behind. Unfortunately what you’ve posted here isn’t enough for me to help you with your problem. Thanks, Rachel

  12. Mårten says:

    Thank you! I spent nearly 15 minutes being annoyed by this before finding this post 🙂

  13. Morgan says:

    Thank you for this post, it literally saved my day !!

  14. Travis says:

    Thanks for this solution. Can you tell me how exactly I can do it the SelectedValue and SelectedValuePath in my example (on StackOverflow)? :

    • Rachel says:

      Hi Travis, I left a comment on your SO post about that, and have also updated my post here to give a short code sample. If it’s still unclear, let me know.


    • Daniel unsworth says:

      Followed you example on stackoverflow works very well thank you was stuck on this 🙂

  15. Travis says:


    I used your idea of override Equals for my combobox SelectedItem not updateing issue. I would like to know how to actually get the alternative method using SelectedValue and SelectedValuePath to work in my example. I have tried several times, and just can’t get it! And, which method is “better”? I was told I should also override GetHashCode if I override Equals(), is this true or needed?

    My OP concerning this is on StackOverflow @


    • Rachel says:

      Personally I think which method is “better” depends on how your data is structured. I prefer to use SelectedValue instead of SelectedItem in most cases, but both methods are viable.

      And yes, if you override .Equals() you should probably overwrite .GetHashCode() too. See this SO question for more information about why.

  16. Vikram says:

    Thanks a lot for the post 🙂

  17. xiaoyuanfxy says:

    Thanks for this post. It really helped me out 🙂

  18. Vesela Gerasimova says:

    This is great post, saved me lots of work and depression 🙂 One more thing: in Equals method be careful to compare only value types.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: