W
What it took to stop creating datagridview events
Guest
Problem:
Had two DataGridviews and either one would modify the contents of the other. Unfortunately this caused VB to call events in a very strange order. After 3 days of working on this one problem I've managed to fix it. But boy, this control is a doozy to work with. Makes me hark back for the days of VB 6.
Solution:
1) used a global inhibit so if one events calls the other events are inhibited
2) used Application.DoEvents() to flush out unwanted events before releasing this inhibit
3) changed selection to a global as unwanted calls to the function it was in were messing up its value
4) added a timer to clear inhibits as clearing them in the events allowed other unwanted events to creep in
5) wrote isuserclick() to test if event triggered was actually from a user clicking that specific control at that location
6) tried to clear the selection on DataBindingComplete event, but that event is never called
All of these methods (except the last one) are needed to stop VB messing things up. I've tried removing one or other, and it stops working again. Just so that the user can use either DataGridview to update the other. Considered deregistering the specific events at specific times from Windows event handler, but decided not to as this could stop events I do want. This would have been my next attempted solution if all the above efforts were still not enough. Failing all of that I would have had to manually poll the mouse coordinates and buttons and then draw everything myself from scratch effectively replacing the DataGridview with my own custom control.
I think that once you get to the point that the only solution is to not use the control or write your own custom control, then the control on offer is a bad one. I found dozens of posts online with the same issues and it had experienced programmers pulling their hair out. Found that it took all of the solutions added together (had to fix most as they no longer work) plus a ton of ugly inhibit checks to finally get each DataGridView to respond to a real user generated event.
Continue reading...
Had two DataGridviews and either one would modify the contents of the other. Unfortunately this caused VB to call events in a very strange order. After 3 days of working on this one problem I've managed to fix it. But boy, this control is a doozy to work with. Makes me hark back for the days of VB 6.
Solution:
1) used a global inhibit so if one events calls the other events are inhibited
2) used Application.DoEvents() to flush out unwanted events before releasing this inhibit
3) changed selection to a global as unwanted calls to the function it was in were messing up its value
4) added a timer to clear inhibits as clearing them in the events allowed other unwanted events to creep in
5) wrote isuserclick() to test if event triggered was actually from a user clicking that specific control at that location
6) tried to clear the selection on DataBindingComplete event, but that event is never called
All of these methods (except the last one) are needed to stop VB messing things up. I've tried removing one or other, and it stops working again. Just so that the user can use either DataGridview to update the other. Considered deregistering the specific events at specific times from Windows event handler, but decided not to as this could stop events I do want. This would have been my next attempted solution if all the above efforts were still not enough. Failing all of that I would have had to manually poll the mouse coordinates and buttons and then draw everything myself from scratch effectively replacing the DataGridview with my own custom control.
I think that once you get to the point that the only solution is to not use the control or write your own custom control, then the control on offer is a bad one. I found dozens of posts online with the same issues and it had experienced programmers pulling their hair out. Found that it took all of the solutions added together (had to fix most as they no longer work) plus a ton of ugly inhibit checks to finally get each DataGridView to respond to a real user generated event.
Continue reading...