gpt4 book ai didi

vb.net - 如果用户单击该行并将焦点从该行移开,则重置 DataGridView 空白行

转载 作者:行者123 更新时间:2023-12-02 07:25:36 25 4
gpt4 key购买 nike

如果用户单击 DataGridView 底部的空白行并将焦点从 DataGridView 移开,则现在单击的行将处于指示对该行进行更改的状态。

是否可以告诉 DataGridView 取消将此行标记为已更改?

当焦点离开 DataGridView 时是否可以重置此行?

如果“发票开具”留空,我们将使用以下事件处理程序来提醒用户:

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

如果用户只是单击网格然后单击表单中的其他位置,我们似乎需要一种方法来阻止此操作的执行。

最佳答案

你可以尝试这样的事情:

Private Sub dg_CellValidating(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

请告诉我是否有帮助。 =)

关于vb.net - 如果用户单击该行并将焦点从该行移开,则重置 DataGridView 空白行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10663623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com