开发者

Way to get AutoComplete working in a DataGridViewComboBoxColumn?

I've already successfully gotten autocomplete working in a regular combo box. I used the leave event to set the selection to null if the user types in some开发者_如何学Cthing that isn't in the list.

Now, I want to do this in a DataGridViewComboBoxColumn. However, the usual properties like AutoCompleteMode and AutoCompleteSource are missing. I hear there's a way get this done using casting somehow but I can't read the VB language instructions too well. Ideally I want to make a new derived class so I can easily use this thing over and over.

The other problem is I need to know what event to intercept in order to reset the combobox to its old value or null if the item isn't in the list.

Help would be appreciated! Thanks.


You can get this feature by implementing the EditingControlShowing event of the grid. Essentially when you edit a combobox column, the editing control is a combobox So by casting you can setup the properties for Autocomplete

void grdPerformanceScenario_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (e.Control is ComboBox)
        {
            (e.Control as ComboBox).AutoCompleteMode = AutoCompleteMode.Suggest;
            (e.Control as ComboBox).AutoCompleteSource = AutoCompleteSource.ListItems;
        }
    }


There is a AutoComplete for DataGridViewComboBoxColumn.

For example:

DataGridViewComboBoxColumn comboBox = DataGridViewComboBoxColumn();
combobox.AutoComplete = true;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜