C# Programming
09-16-2009, 07:02 AM
Hi
Is it possible to add a new item to a ComboBox when its bound to a DataView? Here's the code I use to fill my ComboBox:
DataView dv = new DataView(someDataTable, "FunctionID > '0'", "Function", DataViewRowState.OriginalRows);
cboFunctions.ItemsSource = dv;
cboFunctions.DisplayMemberPath = someDataTable.Columns[1].ToString();
cboFunctions.SelectedValuePath = someDataTable.Columns[0].ToString();
cboFunctions.SelectedIndex = 0;
I tried adding a new item like this:
cboFunctions.Items.Insert(0, "-Please select a part function-");
This gives me a error. The whole idea is to have a combobox item that is kind of like a dummy item just saying something like "-Please select-"
Is it possible to add a new item to a ComboBox when its bound to a DataView? Here's the code I use to fill my ComboBox:
DataView dv = new DataView(someDataTable, "FunctionID > '0'", "Function", DataViewRowState.OriginalRows);
cboFunctions.ItemsSource = dv;
cboFunctions.DisplayMemberPath = someDataTable.Columns[1].ToString();
cboFunctions.SelectedValuePath = someDataTable.Columns[0].ToString();
cboFunctions.SelectedIndex = 0;
I tried adding a new item like this:
cboFunctions.Items.Insert(0, "-Please select a part function-");
This gives me a error. The whole idea is to have a combobox item that is kind of like a dummy item just saying something like "-Please select-"