1) Add a conditional statement in the event handler code to only execute when required. Cell Validating -= new Data Grid View Cell Validating Event Args(dgv Sub Contractor_Cell Validating); it says that "Error 7 'System. hey what do ouy mena by the below private void data Grid View1_Cell Validating(object sender, Data Grid View Cell Validating Event Args e) if (adding Row) - is to call the button event for adding a new row is it every time the cell validating event triggers and a value is entered in the datagridview cell right??2) Detach the event hander before the unwanted event triggers and re-attach after. so when i click the add button the cell validating event triggers i have posted the cell validating event do you know how to solve this thanxxx code!!!2) Detach the event hander before the unwanted event triggers and re-attach after.
In other cases, such as when modifying existing values in the grid, validation would be done at the cell level because "normally" you would allow the user to change the value of only one cell.Normally, the Error Description property would be set in either the Leaving Edit event of a cell or in the Ending Edit event of a row and reset in the Edit Left event of the cell or in the Edit Ended event of the row (see Example 4). Depending on the settings of the grid's Error Behaviors property, (by default) a tooltip will be displayed when the mouse cursor passes over the cell whose value failed the validation process, the cell will blink with a red background color, a tooltip will appear on the corresponding row's row selector, and the error icon displayed in the row selector will blink. 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.Since you have not added your new row yet it should validate OK.By default, if the value of a cell does not pass the validation process, the cell will exit edit mode and the value of the cell will be returned to its original valid value.Custom validation can be provided at either the row or the cell level depending on the kind of validation you want to provide.The Cell Editor Manager's Validate method can be used to validate if the editor's value is valid before it is assigned to the underlying cell.In addition to the built-in validation provided by the Validate method, the Validating event can be handled to provide additional validation criteria.Custom cell validation is done using the Leaving Edit and Validation Error events.In the Leaving Edit event, the custom validation is provided and in the Validation Error event, you can decided if you want to allow the cell to exit edit mode in the case where its value does not pass the validation process (see Example 2).