开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜