Datagridview problems with a warning message

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
Hi,

I have a datagridview that is populated by a bindingsource.

The idea is that if a column has a given value and the user clicks on it a warning message is displayed and this works ok until it is the first row that has this value.

What happens is that as the program loads the message appears a number of times. If I select the tabpage that the dgv is on the message appears as the dgv selection changed event is firing.

How do I stop this event firing as each time the user changes from one tabpage then back the message appears?

Thx
 
You don't stop the event being raised. You simply don't act on it when it's no appropriate. You can either use the AddHandler and RemoveHandler statements to decide if and when the event should be handled at all, or you can simply place an If statement inside your event handler and choose whether or not to display your message based on some condition.
 
I have not tried the addhandler/remove handler approach but have tried the if statement way prior to my post with no success.

In the tabpage selected index change handler I set a boolean value to True in the section that deals with the specific page.

The dgv data is refreashed by a tableadapter.fill call

then the flag is cleared.

In the dgv selection change event I have it set that the code should only run if the flag is false.

But from what I can see the dgv is getting updated sometime after I have cleared the flag in the tabpage selected index change event.

In fact just debugging I see that the dgv event gets called before the tabpage event? So I do not know where to trap this?
So the dgv code ends up running?

I can see where I can set the flag to remain set until after the dgv has refreshed?
 
Back
Top