什么奇怪的行为在AutoComplete在DataGridViewCombobox列? [英] What a strange behavior in AutoComplete in DataGridViewCombobox column?

查看:266
本文介绍了什么奇怪的行为在AutoComplete在DataGridViewCombobox列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用( EditingControlShowing )事件在DataGridViewComboBox列中启用AutoComplete。

I am using the (EditingControlShowing) event to Enable AutoComplete in DataGridViewComboBox Column.

private void dataGridView1_EditingControlShowing(object sender,  DataGridViewEditingControlShowingEventArgs e)
{
    if (e.Control is DataGridViewComboBoxEditingControl)
    {
        ComboBox combo = (ComboBox)e.Control;
        ((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
        ((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.ListItems;
        ((ComboBox)e.Control).AutoCompleteMode =  System.Windows.Forms.AutoCompleteMode.SuggestAppend;
    }
}

但它有一个奇怪的行为,字符,然后我离开单元格(Tab或右键),值没有改变。

但是如果我重复,那么值会改变。
此处,您可以下载源代码和(EXE )

But it has a strange behavior, when I type some characters then I leave the cell (Tab or right key), the value did not change.
But if I repeat that, the value will change. From Here, you can download the source code and (EXE) video that explains the problem.

推荐答案

看来,对于组合框中的第一个条目,选项卡不再触发值的提交。不知道为什么会这样,但似乎处理 CurrentCellDirtyStateChanged 并提交编辑修复它。

It appears that for that first entry into the combobox the tab no longer triggers the commit of the value. No idea why this is so, but it appears that handling CurrentCellDirtyStateChanged and committing the edit fixes it.

void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
    // You could also check here to see if the cell in question is the combobox
    if (dataGridView1.IsCurrentCellDirty)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}

这篇关于什么奇怪的行为在AutoComplete在DataGridViewCombobox列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆