C datagridview rowvalidating We chat cyber sex

At this point the user is not allowed to cancel the performed changes, pressing the Esc key.Hello, I recently setup my Data Grid View to use the Row Validating event.

c datagridview rowvalidating-40c datagridview rowvalidating-66

However, whenever a user types something in to a New Row (as to cause the DGV to create a new row and consider the current row's New Row = false) and then hit escape to cancel the edit, the Data Error exception goes nuts.

It keeps spitting out "Index 4 does not exist" in what seems to be an infinite loop. Row Index] in the Row Validating event, it works fine (but obviously doesn't validate like it should).

Here is my Row Validating code: Note: I have determined that any access to dgv Main. Row Index] (EVEN TO CHECK IF ITS NULL) will cause the dataerror to go nuts when hitting the escape key. Also, if I try to Watch anything in the de****, it says the DGV has 6 rows (it should have had 6 before, 5 after you hit escape and cancel the edit). Rows[4] it times out and then my debugging doesnt work anymore after that, but if I try to view any other row it works fine. Is there anyway I can get this to work, or to disable the ability to cancel editing with the Escape key Thanks-Adam Does anyone know how I can work around this This is a pretty big issue.

This kind of seems like a bug in the framework, but I'm really not too sure. The end-users are losing their data (if they don't commit it) whenever they hit escape because it's causing them to have to kill the program.

This funtionality can be easily implemented by handling the Preview Key Down event, which will revert the row changes after pressing the Esc key.

Let's assume that the If the user enters empty string for a specific cell and tries to navigate to another row, the validation fails and the Error Text is displayed on the corresponding row.

Thanks again Mark, I got one more scenario that I would like to run by you to see if you can help.

Using the test code that I provided before, try changing the query to do a "SELECT TOP 0 * FROM Customers" as to create a databound Data Grid View - only with 0 records.

However, the user may prefer to validate all the data cells in a row at once.

This scenario can be achieved by using the Row Validating event, which is fired when the user tries to change the current row (changing to another row or when the control loses focus).

provides a convenient way to realize data validation before it is committed to the underlying data source.