Clear ComboBox text in DataGridView

3.8k Views Asked by At

I have 2 ComboBox in DataGridView (DataGridViewComboBox), let say Type ComboBox ("Type I" & "Type II") and Options ComboBox. DataGridView and Type ComboBox datasource are set when Form Load. Options ComboBox datasource depend on Type ComboBox selected value.

If Type combobox selected value set to "Type I" then "Options" combobox is enabled, then if Type combobox selected value set to "Type II" then "Options" combobox is disabled.

The problem is, when I input "Type I", and I input "Options" and commit. Then I edit "Type I" to "Type II", I set "Options" combobox datasource to null and disabled it, but "Options" combobox text still display last selectedMember text.

How to clear "Options" combobox text when I edit "Type" combobox ?

3

There are 3 best solutions below

0
On

Try to set "SelectedIndex = -1" of option combobox on selectedIndexChange event of combobox TypeI.

OptionsComboBox.SelectedIndex = -1;

0
On
((ComboBox)field).SelectedIndex = 0;

// It will reset the combobox ... // in my code, --select-- is at index 0

0
On

I know this is old, but for those of you looking for this setting the DataGridViewComboBoxCell value to null allows you to clear the box.

i.e.

((DataGridViewComboBoxCell)dgvGridViewName.Rows[e.RowIndex].Cells[%ColumnName%]).Value = null;