通过点击离开并按Enter键退出datagridview单元格编辑有什么区别? [英] What is the difference between exiting a datagridview cell edit by clicking away and by pressing enter?

查看:273
本文介绍了通过点击离开并按Enter键退出datagridview单元格编辑有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的datagridview的CellEndEdit事件的前两行是:

The first two lines of the CellEndEdit event of my datagridview are:

if (dgvOptionsData.SortedColumn == null)
            dgvOptionsData.Sort(dgvOptionsData.Columns["GroupNumber"], 0);

DataGridView绑定到一个DataTable。

The DataGridView is bound to a DataTable.

当我通过点击单元格进入CellEndEdit事件时,我得到一个重入错误(操作无效,因为它导致对SetCurrentCellAddressCore函数的重入调用)。如果我按输入进入事件,我不会得到这个错误。一旦gridview被排序,我也不会得到错误,即使我在排序列中编辑一个值。

I am getting a reentrancy error (Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.) at the Sort call ONLY when I enter the CellEndEdit event by clicking away from the cell. If I enter the event by pressing enter I do no get this error. I also don't get the error once gridview is sorted, even if I am editing a value in the sorted column.

我已经重组了我的代码,所以我是不使用CellEndEdit事件,因此这个错误不是一个问题,但我想了解发生了什么,为什么。如果您有任何见解,请通知我。

I have since restructured my code so that I am not using the CellEndEdit event and thus this error is not a problem any more but I would like to understand what was happening and why. If you have any insights please let me know.

感谢
Dan

Thanks Dan

推荐答案

在提交单元格编辑时所采取的动作之间存在细微差别。基本上通过点击你了解点击数据网格视图的另一个单元格。此操作通过网格视图以这种方式处理:

There is a subtle difference between actions that you take to commit cell edit. Basically by clicking away you understand clicking on another cell of data grid view. This action is handled by grid view in this manner:


  • 事件处理程序

    • 选择单元格是活动的(作为参数单击单元格例如(1,1))

      • 提交编辑单元格

        • CellEndEdit处理程序用户代码)

          • 排序网格

            • 将单元格设置为活动(作为无单元格的参数特殊值(-1, 1))
              这会抛出一个错误,因为重新输入这个方法

            请注意,如果您单击其他控件(而不是数据网格),则排序将正常。

            Note that if you click other control (not data grid) your sorting will work fine.

            通过Enter键提交更改只需在CellEndEdit处理程序完成后调用select cell即可。

            Committing changes by Enter key simply invokes select cell as active after CellEndEdit handler is finished.

            这篇关于通过点击离开并按Enter键退出datagridview单元格编辑有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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