Invoking the click method of a button programmatically

我只是一个虾纸丫 提交于 2019-12-02 05:57:12

问题


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.


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/1083637/invoking-the-click-method-of-a-button-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!