VB.NET – Reset the DataGridView blank line if the user moves the row and move the focus from the row

If the user clicks on the blank row at the bottom of the DataGridView and removes the focus from the DataGridView, the clicked row is now in a state indicating changes to the row.

Can you tell the DataGridView to unmark whether the row has been changed?

Can this row be reset when the focus leaves the DataGridView?

We use the following event handlers to remind users if Invoiced On is left blank:

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's 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 looks like we need a way to prevent execution if the user Just click on the grid and click elsewhere in the form.

you can try this Things:

Private Sub dg_CellValid ating(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs) Handles dg.CellValidating
Dim headerText As String = dg.Columns(e.ColumnIndex).HeaderText

'Try this ---- -------------------------------------------------- --------
Dim vClicked As Boolean = False
If (Control.MouseButtons And MouseButtons.Left) = MouseButtons.Left Then
vClicked = True
End If
'--------------------------------------------- --------------------------

'Validate the Invoiced On cell and display the error if it's empty.
'And put vClicked here
If Not vClicked AndAlso (String.IsNullOrEmpty(e.FormattedValue.ToString()) And headerText.Equals("Invoiced On")) Then

dg. Rows(e.RowIndex).ErrorText = "Please enter an Inoiced On date."

e.Cancel = True
End If
End Sub

Please let me know if it helps. =)

If the user clicks on the blank row at the bottom of the DataGridView and removes the focus from the DataGridView, the row that is now clicked It is in the state of indicating to change the row.

Can you tell the DataGridView to unmark whether the row has been changed?

Can this row be reset when the focus leaves the DataGridView?

We use the following event handlers to remind users if Invoiced On is left blank:

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's 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 looks like we need a way to prevent execution if the user Just click on the grid and click elsewhere in the form.

You can try something like this:

Private Sub dg_CellValidating(ByVal sender As Object, ByVal e As DataGridViewCell ValidatingEventArgs) Handles dg.CellValidating
Dim headerText As String = dg.Columns(e.ColumnIndex).HeaderText

'Try this -------------- ------------------------------------------------
Dim vClicked As Boolean = False
If (Control.MouseButtons And MouseButtons.Left) = MouseButtons.Left Then
vClicked = True
End If
'----- -------------------------------------------------- ----------------

'Validate the Invoiced On cell and display the error if it's empty.
'And put vClicked here
If Not vClicked AndAlso (String.IsNullOrEmpty(e.FormattedValue.ToString()) And headerText.Equals("Invoiced On")) Then

dg.Rows(e.RowIndex).ErrorText = " Please enter an Inoiced On date."

e.Cancel = True
End If
End Sub

Please tell me if it helps. =)

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3400 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.