Master-detail datagridviews:RowValidating& CellValidating on details DGV无法阻止用户离开无效单元格 [英] Master-detail datagridviews : RowValidating & CellValidating on details DGV fail to prevent user from leaving invalid cell

查看:72
本文介绍了Master-detail datagridviews:RowValidating& CellValidating on details DGV无法阻止用户离开无效单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WinForms应用中。我有主要的细节DatagridViews。

i在详细网格上有一个RowValidating和CellValidating事件处理程序。



如果细节单元格/行验证失败,我将e.Cancel设置为TRUE。

这可以防止用户在细节网格中留下单元格/行,除了一种情况:



当用户在详细信息单元格中插入无效数据时直接将焦点移动到主网格到不是其父节点的记录,然后用户不会被阻止离开该无效单元格!



更多,当我返回时对于无效的单元格,我发现无效的值不被接受,并且单元格具有旧值。



另一种情况:如果我删除单元格的值而不是插入无效值,e.Cancel也设置为TRUE,因为该值是必需的。我重复上一个场景,当我回到那个单元格时,我发现它是EMPTY,甚至没有它的旧价值...



无论如何可以告诉我如何防止用户留下无效的细节单元?

in my WinForms app. i have master-detail DatagridViews.
i have a RowValidating and CellValidating event handlers on detail grid.

if detail cell/row validation fails, i set e.Cancel to TRUE.
this prevents user from leaving cell/row in details grid, EXCEPT in one case :

when user inserts invalid data in details cell and directly moves focus to master grid to a record in which is not its parent, then user is not prevented from leaving that invalid cell !

further more, when i return back to THAT invalid cell, i discover that invalid value wasn't accepted, and cell has its old value.

another case: if i delete cell's value instead of inserting an invalid value, e.Cancel is also set to TRUE because that value is required. i repeat the previous scenario and when i get back to that cell, i find it EMPTY, not even having its old value...

can anyway tell me how to prevent user from leaving invalid detail cell ?

推荐答案

我已经使用一个简单的解决方法解决了这个问题。



详细网格CellValidating,当输入为INVALID时,我执行以下操作:

除了将e.Cancel设置为TRUE之外,我还会显示一个MessageBox来通知用户。用户将单击确定关闭消息框,这足以使焦点保持在详细网格中的无效单元格上。



我希望能帮到别人。
i have solved the problem using a simple workaround.

In detail grid CellValidating, when input is INVALID i do the following:
In addition to setting e.Cancel to TRUE i also display a MessageBox to inform the user. User will click OK to dismiss the message box, and that is enough to keep focus on the invalid cell in detail grid.

i hope that will help others.


这篇关于Master-detail datagridviews:RowValidating& CellValidating on details DGV无法阻止用户离开无效单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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