Kiran
Kiran

Reputation: 8528

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

Upvotes: 2

Views: 9247

Answers (1)

Derek
Derek

Reputation: 8628

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

Upvotes: 6

Related Questions