如何使按钮按下事件更恰当 [英] How to give proprity to button press event

查看:125
本文介绍了如何使按钮按下事件更恰当的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在窗体上具有Datagridview控件和确定"按钮控件.

我有处理网格的CellLeave事件.我已将对话框结果取消"设置为按钮.

当用户按下确定"按钮时,我想关闭表格.但是要在我写了一些验证代码的地方休假,所以我无法关闭表格.

``请告诉我如何检测按钮按下情况,我不希望电池离开.当我按下取消"按钮时,它应该直接关闭表单.

I have Datagridview control and "OK" Button control on form.

I have handle CellLeave event of grid. I have set dialog Result "Cancel" for button.

When user press "Ok" button I want to close form. but it is going to cell leave where I have written some validation code, so I am not able to close form.

''Please tell me how can i detect button press , I dont want cell leave to fire. When I press Cancel button , It should directly close form.

推荐答案

您可以从CellLeave事件中删除处理程序,但是我会有一个类级别的布尔IsClosing在Click处理程序中进行设置,然后对其他所有内容进行测试.
You could remove the handler from the CellLeave Event, but I would have a class level bool IsClosing which I set in the Click handler and test in everything else. It''s a lot clearer, and very simple to implement.


要解决此问题,只需将验证码从CellLeave事件移到ButtonOK_Click事件.
To resolve this problem, just move validation-code from CellLeave event into ButtonOK_Click event.


这篇关于如何使按钮按下事件更恰当的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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