What's the best place to implement validation logic code and conditional formatting code for a DataGridView?
In a lot of books and articles that I've read on this control, it seems to suggest that the appropriate event to handle for this is the CellValidating one. Well, the name more than implies this as well.
However, this event triggers a bit too often for my tastes and I'm not sure it is required. For example, this event triggers everytimes the users switches to another row.
On the other hand, the CellValueChanged event seems to trigger only when the value of the cell changes, which means the validation code runs only when the value changes and not everytime a user changes cells.
Now, since so many books use the CellValidating event, I wonder if there is not any gotcha (in display for example) with using the CellValueChanged?
I understand that the impact in performance should be irrelevant when using simple validation and conditional highlighting rules but I would as much prefer it not to run useless code everytime the user moves to another cell if it can be avoided.
Thanks,
I'm using CellValueChanged currently on a grid with custom validation and have had no problems with display or anything else.
I used this event because I wanted to fire off a certain order of events, but only when the user changes the value of a cell.
I have not noticed much in the way of a performance hit (tested with 100 - 5000 rows).
I think in the end it depends on what your validation needs are. In my case, CellValueChanged has done what I wanted/needed.
EDIT
The biggest thing about the CellValidating event is that you can stop the user from leaving a cell, if the value entered does not pass your validation. I didn't want to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With