Editing Combobox item in Datagridview in C#

Kiran picture Kiran · Dec 7, 2012 · Viewed 7.7k times · Source

I have a Datagridview in Winform. One of the column is a Combobox. Is it possible to set the property such that user can enter apart from being able to select the entries from the dropdown list.

I was able to do it on a Combobox item with a following changes from the properties window:

AutoCompleteMode.SuggestAppend;
AutoCompleteSource.CustomSource;
DropDownStyle : Dropdown;

Thanks

Answer

Derek picture Derek · Dec 7, 2012

Something like this may Help :-

private void DataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    if (DataGridView1.CurrentCell.ColumnIndex == yourComboBoxColum)
    {
        ComboBox combo = e.Control as ComboBox;

        if (combo == null)
            return;

        combo.DropDownStyle = ComboBoxStyle.DropDown;
    }
}