I’ve created my own class c_DataGridView inherited from DataGridView. Now in this class I’ve implemented the event CellEndEdit.
Now I created an instance of this class/control on my form named myGrid1 and then I also implemented the same event of the grid here on my form.
Now when I run the form and edit a cell on the Grid the event trigger sequence is that: first my class c_DataGridView’s CellEndEdit event triggers and then the object’s event implemented on the form triggers.
Is there any possibility that I could manage to trigger the event of c_DataGridView’s object first and then the class’s event itself.
I hope that I have cleared myself.
The order in which event handlers are fired is unpredictable. There’s a standard pattern to deal with this, a .NET class always has a protected method with the same name as the event, prefixed with “On”.
So in your derived class, override the OnCellEndEdit() method instead of subscribing the event. You now have complete control over the way the event is getting handled and fired. You can call base.OnCellEndEdit() first, then write your custom code. Or you can call it last, first writing your custom code. Or you can not call it, preventing the CellEndEdit event from getting fired at all. Clearly you now have complete control over the order, the Right Way depends on what you want to accomplish.