Cell leave cellvalidating
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.It is the same for the three cells that are filled on form load. This is not the case with any of the already loaded values. Unforunately it does not seem to work when i try to add a new row to the grid, enter a value and try to leave the cell. We have a simple datagrid where the first column contains a Vendor Number and the second is a read-only column containing the name of that vendor.Users can freely enter into the first column, and in the Cell Validation event, we verify that the format of what they entered is correct and then lookup the number they entered to populate the second column with the name.The event handler receives an argument of type Cell Validating Event Args containing data related to this event.The following Cell Validating Event Args properties provide information specific to this event.
The default key setting assigns end edit without leaving the current cell action to the "Enter" key.
So the Cell Validating event cannot be fired when pressing the "Enter" key. The following code example shows how to use this event to validate the cell's value.