I have DataTable containing necessary DataRows, which I want to display in ComboBox.
The second DataColumn is called VALUE and I want to make it a DisplayMember.
However, all I see in ComboBox – empty lines according to number of DataRows.
What am I doing wrong?
DataTable dataTableManufacturers;
dm = new DatabaseManagement.DatabaseManagement(Properties.Settings.Default.DBServer,Properties.Settings.Default.DBName, Properties.Settings.Default.DBUser, Properties.Settings.Default.DBPassword);
dataTableManufacturers = dm.getManufacturers();
combxManufacturer.DisplayMemberPath = "VALUE";
foreach (DataRow row in dataTableManufacturers.Rows)
{
combxManufacturer.Items.Add(row);
}
DisplayMemberPathshould be"[VALUE]"because you intend to use this indexer (not a property) to get at the data. See binding path syntax on MSDN for more information.As an (important!) aside, the “WPF way” is to set up the control’s
ItemSourceinstead of manually adding to theItemscollection.