以编程方式调用按钮的单击方法

发布于 2024-07-26 08:08:18 字数 334 浏览 3 评论 0原文

简单的问题(我认为):我希望能够调用预定义对象上的 click 方法,特别是标准 c# BindingNavigator 上的 bindingNavigatorDeleteItem 按钮。 我需要拦截删除,以便我可以验证该记录是否允许被删除。 如果是,我想调用前面提到的单击事件,该事件可以很好地删除所述记录。 如果该记录不符合删除条件,我想中止删除。

我的一位工程同事建议我简单地向工具条添加另一个按钮,并使用它的 click 方法(当然,我可以访问)来检查记录资格,并将原始删除按钮调用为需要。

如果还有其他更好的方法,请转发。

Simple problem (I think): I want to be able to invoke a click method on a predefined object, specifically, the bindingNavigatorDeleteItem button on the standard c# BindingNavigator. I need to intercept the delete so that I can verify that the record is allowed to be deleted. If it is, I want to invoke the aforementioned click event which does a nice job of deleting said record. If the record is not eligible for deletion, I want to abort the delete.

An engineering colleague of mine suggests that I simply add another button to the toolstrip and use it's click method (which, of course, I can get to) to check the records eligibility and call the original delete button as needed.

If there is another, better way, please pass it along.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单身情人 2024-08-02 08:08:18

要简单地调用点击 - 您应该能够使用 PerformClick()

我对你提到的其他事情有点迷失——你能澄清一下吗?

To simply invoke the click - you should be able to use PerformClick().

I was a little lost by the other things you mentioned - can you clarify?

白云不回头 2024-08-02 08:08:18

不要拦截工具条按钮(并向用户保留其他技术,例如删除 DataGrid 中的行),而是使用数据源上的事件之一来取消删除(如果无效)。

Instead of intercepting the toolstrip button (and leaving other techniques open to the user, such as deleting a row within a DataGrid), use one of the events on your Data Source to cancel the delete if invalid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文