Text = "Data Grid View validation demo (disallows empty Company Name)" End Sub Private Sub Form1_Load(By Val sender As System. All Cells Except Header) End Sub Private Sub data Grid View1_Cell Validating(By Val sender As Object, _ By Val e As Data Grid View Cell Validating Event Args) _ Handles data Grid View1. Header Text ' Abort validation if cell is not in the Company Name column. Equals("Company Name") Then Return ' Confirm that the cell is not empty. Load ' Initialize the Binding Source and bind the Data Grid View to it. Data Source = Get Data("select * from Customers") Grid View1. Auto Resize Columns( _ Data Grid View Auto Size Columns Mode.
Add the custom validation rule to the property is set to Updated Value so that the validation occurs only after the bound data object is updated.
Data Grid View Cell Validating Event Handler Data Grid View Cell Validating Event Args Cell Validated Data Grid View Cell On Cell Validating Data Grid View Class System.
column, its value is tested for validity by checking that it is not empty.
When this event is canceled in data-bound mode, the new value is not pushed to the underlying data source.
When this event is canceled in virtual mode, the Cell Value Pushed event will not be raised.