I have a client having a problem with a DataGridView in a Windows app. They are calling the CellValidated event, but they want to have different validation for the cell if it is in a row that is already committed back to the datasource than if it is a row that is first being added (and not yet committed (the user hasn’t left the row yet). I tried the IsNewRow property, but as soon as you start typing in the row, another “new row” is added, so the row you are working with is no longer considered the new row. I know the row has not been committed yet because you can hit Esc to cancel editing, and the entire row goes away.
Is there a way to tell if the currently edited row is actually the “new row” in the sense that it hasn’t been committed back to the datasource?
GenericMeatUnit’s answer didn’t work for me, but it provided me with enough to find a way to make it work. Here’s how I am doing the check now:
This if statement works because before leaving the row in the DataGridView, it doesn’t actually exist in the datatable yet, so the number of rows in the datatable will be equal to the RowIndex for the new row, since RowIndex is zero-based.