Datagridview cellvalidating cancel
Since you have not added your new row yet it should validate OK.
Or if not, then it is because the user has entered an invalid value in the current cell. Something there is causing the cell validating event to fire. [Edit] The validating event is firing because focus is being moved from the DGV to the button.
If there are cells that you dont want to validate (eg read only cells) then add a check at the start of the event handler that will cause it to exit if it is trying to validate those cells.
For instance, if column with index 2 is read only and you dont want to validate cells in that column you could use: If you have attached an event handler to the Cell Validating event then it will always fire when focus leaves the cell.
1) Add a conditional statement in the event handler code to only execute when required.
Cell Validating Event: Occurs when a cell loses input focus, enabling content validation.Causes Validation = false This will ensure when a user has been editing the text box, and decides to Cancel by clicking the btn Cancel, the validation event of the text box event will NOT fire.Moving focus from the text box to any other control on the form will fire the validating event ( that too if the Causes Validation property of the control receiving focus is set to true. 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. Cancel = True End If End Sub Private Sub data Grid View1_Cell End Edit(By Val sender As Object, _ By Val e As System. Cell End Edit ' Clear the row error in case the user presses ESC. For more information, see Protecting Connection Information.