Bipin Joshi is the proprietor of Binary Intellect Consulting, where he conducts premier training programs on . He wears many hats, including software consultant, mentor, prolific author, webmaster, Microsoft MVP, and member of ASPInsiders. Although you used Data Set as the source of your data, you also could have used generic collections if required.You can download the code that accompanies the article here.Notice how the Column Index and Row Index properties of Data Grid View Cell Validating Event Args parameter are used.At run time, if the validation fails, the Data Grid View displays a red exclamation icon in that cell (see below).Hovering the mouse pointer on the icon displays the Error Text that you set earlier.The Data Grid View control of Windows Forms is a versatile control that can help you create professional-looking data entry forms.This property returns the new value entered in the cell.
To perform any custom validation on the cell or row being edited, you can use the Cell Validating and Row Validation events, respectively.If you want to validate the data cell by cell, the former event is useful where you want to validate the data for the entire row at once then the later event is handy.In your example, you use the Cell Validating event, as shown below: Here, you want to ensure that the length of the new Customer ID is at least five characters.You do this by using the Formatted Value property of the Data Grid View Cell Validating Event Args parameter.
It not only supports data binding but also provides frequently needed column types, such as combo box and button.The Data Grid View event model is really extensive and one can take control of validation and entry by using many of these events.