简体   繁体   中英

c# don't want to trigger an event

I have an event that monitors for changes to a datagridview. I don't want this to be triggered when the datagrid is bound for the first time and it's configuration is done. Is it possible to 'opt-out' of triggering an event in certain circumsttances?

Thanks.

You can check for those circumstances in your event handler and choose to do nothing.

Alternately, you can create an event which does nothing but checks for binding and complete configuration, and when that's complete, removes itself and adds the event handler which does what you generally want.

I usually have a private bool _isLoading variable in the form. When I do initial data binding I then set _isLoading to true, and set it to false once data bidning is done. In my events I then check if _isLoading is true, and if it is I just return out of the event method without doing anything.

You may add the handler for the event programmatically at some point. In your case after the firts databind.

DataGrid.yourEvent += new EventHandler(event_Handler);

Doing this you don't need check any boolean variable

You can set a boolean field in your form when first setting the datasource.

In the event, you can return; if the field is true .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM