Search code examples
c#winformsdatagridviewdatagridviewcomboboxcell

Editing Combobox item in Datagridview in C#


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


Solution

  • 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;
        }
    }