Rowvalidating event

Rated 3.89/5 based on 691 customer reviews

I am manually handling the Datasource Update which is dependant on the validations. Let me diverge from the intial description to the REAL Issue.

In the process of validating some cell values the Row Validating Event does not fire when navagation moves off the row. However, if i change a cell value, Tab back to the left to another cell on the same row, then use the mouse to click on a Previous row above the changed row..... Example:: A B C D 1 x x x x 2 x x x x 3 x x x x If I change the value in C2, then backtab (or mouse click) back to B2, Then mouse click on any cell in row 1, the Row Validation Event does not fire and thus the changed value in C2 does not get evaluated.

All I need is to be able to remove the row that the user entered into the grid if it happens to be a duplicate and was not inserted.

Basically, I want the user to see the row disappear after the message is displayed indicating that the record was a duplicate, so that it is obvious and also because if it is not removed then the grid will contain two identical rows.

In this walkthrough, you will retrieve rows from the column and tries to leave the cell, the Cell Validating event handler will examine new company name string to make sure it is not empty; if the new value is an empty string, the Data Grid View will prevent the user's cursor from leaving the cell until a non-empty string is entered.

To copy the code in this topic as a single listing, see How to: Validate Data in the Windows Forms Data Grid View Control.

Leave a Reply