Invoking the click method of a button programmatic

2019-02-26 06:51发布

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.

2条回答
Bombasti
2楼-- · 2019-02-26 07:29

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?

查看更多
Rolldiameter
3楼-- · 2019-02-26 07:40

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.

查看更多
登录 后发表回答