子Datagridview RowValidating事件阻止触发按钮单击事件 [英] Child Datagridview RowValidating event prevents firing button click event

查看:150
本文介绍了子Datagridview RowValidating事件阻止触发按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

i有master-detail DataGridViews和一个保存按钮。

i在我的DataGridView细节上有一个RowValidating事件处理程序,

和按钮单击按钮的事件处理程序。



当我向细节网格添加新行,然后立即单击保存按钮,我希望这些处理程序被执行:RowValidating,ButtonClick

但这不会发生..



RowValidating处理程序被执行,但是从未到达按钮Click处理程序。

i注释掉了我的RowValidating处理程序中的所有代码,问题仍然存在......



i删除RowValidating处理程序,然后才开始(点击处理程序)被执行了。



任何想法可能是什么问题?

i还没有发布任何代码,因为问题甚至存在如果没有在RowValidating处理程序中写入代码

提前感谢

hello,
i have master-detail DataGridViews and a save button.
i have a RowValidating event handler on my detail DataGridView,
and a button Click event handler for the button.

when i add a new row to detail grid, and then immediately click the save button, i expect these handlers to be executed : RowValidating , ButtonClick
but that doesn't happen..

RowValidating handler gets executed, but button Click handler is never reached.
i commented out all code in my RowValidating handler, and the problem was still there...

i deleted RowValidating handler, and only then ( Click handler) was executed.

any idea what the problem could be?
i haven't posted any code, because the problem is there even if no code is written within the RowValidating handler
thanks in advance

推荐答案

ih ave解决了这个问题:



i set CausesValidation保存按钮的属性为FALSE,因此在更改网格中的值后立即单击按钮时,RowValidating事件永远不会被解雇并确保验证网格行,我只是在buttonClick事件处理程序中调用this.Validate()方法。这个方法会激活控件的验证事件,当点击按钮时,控件会失去焦点。



在我的情况下,当我在网格中编辑一行时,点击按钮,触发buttonClick,并调用form.validate(),然后在我最近修改的网格行上调用RowValidating。
i have solved it like this :

i set CausesValidation Property of the save button to FALSE, so when the button is clicked immediately after changing a value in the grid, the RowValidating event is never fired. and to insure validation the the grid row, i just called this.Validate() method inside the buttonClick event handler. this method will fire validation events for the control which lost focus when the button was clicked.

in my case, when i edit a row in the grid, and click the button, the buttonClick is fired, and form.validate() is called, which in turn calls RowValidating on my lately modified grid row.


这篇关于子Datagridview RowValidating事件阻止触发按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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