Avinash Singh
Avinash Singh

Reputation: 2785

How to Clear ComboBox items in SelectionChanged Event of another combobox

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

Answers (2)

Ramji
Ramji

Reputation: 43

Just give this code

   comboBox1.Items.Clear()

Upvotes: 0

Furqan Safdar
Furqan Safdar

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

Related Questions