Juliano Oliveira
Juliano Oliveira

Reputation: 928

Select value to be shown in combobox list from an ItemsSource class in C# and WPF

I'm developing an application that use a combobox in wpf. I'm using a class that contain two values ID and Name, I'm bulding a list with this class to be the ItemsSource of the combobox, as follow:

Example.cs

foreach (XmlNode OEM in OEMs)
{
    string OEMname = OEM.Attributes["OEMname"].InnerText;
    int ID = Int32.Parse(OEM.Attributes["ID"].InnerText);

    OEM oem = new OEM { OEMname = OEMname, ID = ID};

    oems.Add(oem);
}

cbxSelOEM.ItemsSource = oems;

My problem is the value shown in the combobox, instead of show the OEMname value they show other name, I believe that is the object name in the list. How can I solve this problem?

Upvotes: 1

Views: 142

Answers (1)

Fruchtzwerg
Fruchtzwerg

Reputation: 11389

Typically the ToString() of objects is shown at the ComboBox. To show the OEMname simply set the DisplayMemberPath like

cbxSelOEM.DisplayMemberPath = "OEMname";

Upvotes: 2

Related Questions