Reputation: 2785
i have two ComboBoxes in WPF Application...
in first ComboBox SelectionChanged Event i want to clear Second CombBox items....
private void cmbBoard_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
cmbClass.DataContext = this;
cmbClass.Items.Clear();
CVariables.StrSQLQueryPub = "select ClassID,Class from QB_Class WHERE BoardID='" + strBoardId + "' ORDER BY Class";
CFunctions.fnToFillDataTable(CFunctions.Con, CVariables.StrSQLQueryPub);
DataTable dt = CVariables.DTable;
cmbClass.ItemsSource = dt.DefaultView;
cmbClass.DisplayMemberPath = "Class";
cmbClass.SelectedValuePath = "ClassID";
}
Upvotes: 0
Views: 1066
Reputation: 16728
Simply just call the Clear()
method on Items
property of the ComboBox
.
cmbClass.Items.Clear();
You are doing it right in your piece of code but later you are also populating it with dt.DefaultView
. So this way you might not be having the expected outcome.
Upvotes: 1