Sukram
Sukram

Reputation: 466

WPF ComboBox: Wrong Item is displayed

This is the initial situation:

XAML:

<ComboBox Grid.Row="0"
           Grid.Column="1"
           Margin="0,3"
           HorizontalAlignment="Stretch"
           DisplayMemberPath="DisplayText"
           ItemsSource="{Binding ObjectSource}" />

ViewModel:

public Collection<MyObjects> ObjectSource
{
    get
    {
        return this.objectSource;
    }

    set
    {
        this.SetProperty(ref this.objectSource, value);
    }
}

My Objects contains a name (string), valid from (dateTime) and a displayText (string only get) which combine the name and valid from for displaying.

In this easy situation I am able to open the combobox an see all entries, after selecting one it also display the right displaytext inside the combobox. Now I open the the dropdown area again and select an other entry. The result is that the slected item switched (as you can see the highligthed item when open the dropdown entry again). But the displayed item inside the combobox does not changed, there is still the DisplayText of the first selection.

Screenshot of the result situation

Does anybody has an idea for me why the combobox does not update? Thanks in advance

Edit: Thanks all for their help. Problem was a buggy overriding of Equals.

Upvotes: 6

Views: 775

Answers (1)

blindmeis
blindmeis

Reputation: 22445

just for completeness :)

you have to check your Equals() override and make sure thats not buggy. i had the same problem with a listbox these days.

Upvotes: 2

Related Questions