If the user clicks an empty row at the bottom of the DataGridView and moves the focus away from the DataGridView, now the row click is in a state indicating that changes to this row have been made.
Can I tell the DataGridView to cancel this row as changed?
Is it possible to reset this line when the focus is disconnected from the DataGridView?
We use the following event handler to alert the user if Invoiced On remains empty:
Private Sub dataGridViewPayments_CellValidating(ByVal sender As Object, _ ByVal e As DataGridViewCellValidatingEventArgs) _ Handles DataGridViewPayments.CellValidating Dim headerText As String = _ DataGridViewPayments.Columns(e.ColumnIndex).HeaderText ' Validate the Invoiced On cell and display the error if it empty. '------------------------------------------------------------------- If (String.IsNullOrEmpty(e.FormattedValue.ToString()) And headerText.Equals("Invoiced On")) Then DataGridViewPayments.Rows(e.RowIndex).ErrorText = _ "Please enter an Inoiced On date." e.Cancel = True End If End Sub
It seems like we need a way to stop this from being executed if the user just clicks on the grid and then clicks elsewhere on the form.
source share