What's the best place to implement validation logic code and conditional formatting code for a Data Grid View?
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 Cell Validating one. However, this event triggers a bit too often for my tastes and I'm not sure it is required.
From within that event, you can indicate that the user's value is invalid by setting the Error Text value of the cell or row.
If a cell doesn't satisfy some conditions in Cell Validating event, I want the cell's value to be changed to the old value when I leave the cell.
Error Message) End Sub Um, the Cell Validating event is not for formatting; it's for validating.
The point of the Cell Validating event is for you to test the contents of the cell and determine whether it satisfies one or more conditions and reject it if it doesn't.
Column Index Case 2 'This is the Load Value column If e. Text) End If End If str Cell Value = Get Decimal Places(get Output Null(Real Read Mode, cmb Output Unit. ", e) bln Error = True Else s Load Amt = Get Load Amount(col IDX - 1, row IDX) str Cell Value = Get Decimal Places(get Output(Real Read Mode, cmb Output Unit. What if the column was bound to a numeric property and the input wasn't numeric?
Checked Then If Not bln0Load Performed Then bln0Load Performed = True Nullify System(DM, cmb Output Unit. Value) Then Check Error Status("Previous row has no output value! The Value of the cell hasn't actually changed when Cell Validating is raised because the contents hasn't yet been validated so might not be accepted.
It doesn't actually look like formatting is what you're doing anyway.
Row Index End If Case 3 'This is the Output column If e. Text, 0), g Load Decimal Places) Else If row IDX 0 And Is Nothing(c DGV. Text, s Load Amt), g Load Decimal Places) End If End If End Select c DGV. How could the Value have changed if doing so would break that binding?