0
votes

I have a DataGridView control that has a TextBox Column. On the DataGridView.CellValidating event, I use the following code to verify that the entry is an acceptable date:

dgvStartingGrid.EndEdit()
Dim dteStartTime As DateTime
If Not Date.TryParse(dgvStartingGrid.CurrentRow.Cells(4).Value, dteStartTime) Then
    MessageBox.Show("Please enter a starting time in one of the following formats:" & vbCrLf & _
    vbCrLf & "- MM/DD/YY HH:MM:SS (24 Hour Format)" & vbCrLf & "- HH:MM:SS (24 Hour Format)" & _
    vbCrLf & "- HH:MM:SS (AM/PM) (12 Hour Format)", "Start Time Entry Error")
    e.Cancel = True
End If

This code works fine the first time the cell is edited.

The trouble that I am having is that IF I enter a valid date, and then later come back to the cell and enter an invalid date, on the CellValidating event, it skips over this If...End If block because it shows that the current cell value is the old valid date, not the invalid entry that is currently in the cell.

How do I commit or get the invalid value that currently resides in the DataGridView cell?

Thanks

1

1 Answers

1
votes

Use the CellValidated event instead.

CellValidating event is called before replacing the new cell value