Reputation: 928
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
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