DataGridView中自动完成组合框列不保留在原始细胞休假值 [英] DataGridView autoComplete comboBox column not retaining values on initial cell leave

查看:188
本文介绍了DataGridView中自动完成组合框列不保留在原始细胞休假值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自动完成组合框柱绑定的dataGridView,并自动完成工作,只是我观察一个动作那升技刺激性。



当我第一次键入自动完成单元格文本并移动到与tabKey下一个单元格,我的选择是不保留,永远我选择了什么被清除,自动完成单元格为空。如果是Ⅱ立即使用左箭头键返回到自动完成单元格并键入文字,我选择保留有任何问题,什么都。



所以,这个问题我有越来越细胞保留我的第一个初始选择,只有现在的工作解决方法是按Tab切换到下一个单元格,然后返回到本问题自动完成组合框细胞并做打字都全了。在这点上,它的工作原理。



难道还有一些事件中,我应该处理提交对细胞我选定的文本离开



代码:<? / p>

 私人无效dataGridView1_EditingControlShowing(对象发件人,DataGridViewEditingControlShowingEventArgs E)
{
如果(e.Control是组合框)
{
((组合框)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
((组合框)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
((组合框)e.Control).AutoCompleteSource = AutoCompleteSource.ListItems;
}
}



编辑:在下面CellLeave,值也返回空,即使我已经做出了选择。

 私人无效dataGridView1_CellLeave(对象发件人,DataGridViewCellEventArgs E)
{
无功行= this.dataGridView1.CurrentRow.Index;
字符串值= this.dataGridView1 [ITEMID行] .Value.ToString();
}


解决方案

处理CurrentCellDirtyStateChanged事件解决的问题,我希望它不会导致到一些其他的问题,但!

 私人无效dataGridView1_CurrentCellDirtyStateChanged(对象发件人,EventArgs五)
{
如果(dataGridView1.IsCurrentCellDirty)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}


I have a bound dataGridView with an autoComplete combobox column and the autocomplete is working except that am observing one behaviour thats abit irritating.

When i type text in the autocomplete cell for the first time and move to the next cell with the tabKey, my selection is not retained, what ever i selected is cleared and the autocomplete cell is left null. If ii immediately use the left arrow key to return to that autocomplete cell and type in text, what ever i select is retained with out any issues.

So, the problem am having is getting the cell retain my very first initial selection, the only work around now is to Tab to the next cell, then return back to this problematic autoComplete combobox cell and do the typing all all-over. At this point, it works.

Could there be some event i should handle to commit my selected text on cell leave?

Code:

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

Edit: On CellLeave below, value is also returned as null even when i have made a selection.

 private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
    {
        var Row = this.dataGridView1.CurrentRow.Index;
        string value = this.dataGridView1["itemID", Row].Value.ToString();
    }

解决方案

handling the CurrentCellDirtyStateChanged event resolved the issue, i hope it doesn't result into some other issue though!

 private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (dataGridView1.IsCurrentCellDirty)
            {
                dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
            }
        }

这篇关于DataGridView中自动完成组合框列不保留在原始细胞休假值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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