share
Stack OverflowHow to set AutoComplete for a DataGridView Combobox Column
[+2] [1] ruedi
[2016-08-18 08:21:49]
[ c# .net winforms datagridview combobox ]
[ https://stackoverflow.com/questions/39013204/how-to-set-autocomplete-for-a-datagridview-combobox-column ]

I have a DGV, connected to a DataSet which is connected to a database, with 8 columns. One of these columns is a combobox with the following settings

enter image description here

At the moment the autocomplete (by default) works like this: If I type in 'a' I get all entries starting with 'a'. But that's it. If I type in 'An' it does not go to e.g. Andalusia.

I already checked the combobox settings, where you can set the autocomplete mode and source and so an but then I saw, that I do not have these settings within the properties you can see above.

Does anyone know how I can get the autocomplete I would like to have accomplished?

(2) Possible duplicate of How to Suggest Append ComboBox in DataGridView? - Ian Goldby
[+9] [2016-08-18 10:10:03] Reza Aghaei [ACCEPTED]

You can handle EditingControlShowing [1] event of DataGridView and using Control property of the event argument, get DataGridViewComboBoxEditingControl [2] which is derived from ComboBox.

Then you can set its AutoCompleteMode [3] to available options. You also should set its DropDownStyle [4] property to ComboBoxStyle.DropDown to let the user type in control.

void grid_EditingControlShowing(object s, DataGridViewEditingControlShowingEventArgs e)
{
    var comboBox = e.Control as DataGridViewComboBoxEditingControl;
    if(comboBox!=null)
    {
        comboBox.DropDownStyle = ComboBoxStyle.DropDown;
        comboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
    }
}
[1] https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.editingcontrolshowing?WT.mc_id=DT-MVP-5003235&view=netframework-4.8
[2] https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridviewcomboboxeditingcontrol?WT.mc_id=DT-MVP-5003235&view=netframework-4.8
[3] https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.autocompletemode?WT.mc_id=DT-MVP-5003235&view=netframework-4.8
[4] https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.dropdownstyle?WT.mc_id=DT-MVP-5003235&view=netframework-4.8

(1) Since I posted answer as C#, I'll add C# tag to the question. - Reza Aghaei
1