VB.NET中,当用户点击某行后移除焦点,如何重置DataGridView的空白行?

2026-05-06 13:242阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计389个文字,预计阅读时间需要2分钟。

VB.NET中,当用户点击某行后移除焦点,如何重置DataGridView的空白行?

如果用户单击DataGridView底部的空白行并将焦点移出,此时单击的行将处于待编辑状态,并显示对该行进行编辑的状态。是否可以告诉DataGridView取消标记该行是否已被修改?焦点离开DataGridView时,系统会自动判断该行是否进行了修改,并相应地更新其状态。

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

是否可以告诉DataGridView取消标记该行是否被更改?

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

我们使用以下事件处理程序来提醒用户,如果将Invoiced On留空:

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

看起来我们需要一种方法来阻止执行,如果用户只需单击网格然后单击表单中的其他位置.

VB.NET中,当用户点击某行后移除焦点,如何重置DataGridView的空白行?

你可以尝试这样的事情:

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

请告诉我它是否有帮助. =)

本文共计389个文字,预计阅读时间需要2分钟。

VB.NET中,当用户点击某行后移除焦点,如何重置DataGridView的空白行?

如果用户单击DataGridView底部的空白行并将焦点移出,此时单击的行将处于待编辑状态,并显示对该行进行编辑的状态。是否可以告诉DataGridView取消标记该行是否已被修改?焦点离开DataGridView时,系统会自动判断该行是否进行了修改,并相应地更新其状态。

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

是否可以告诉DataGridView取消标记该行是否被更改?

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

我们使用以下事件处理程序来提醒用户,如果将Invoiced On留空:

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

看起来我们需要一种方法来阻止执行,如果用户只需单击网格然后单击表单中的其他位置.

VB.NET中,当用户点击某行后移除焦点,如何重置DataGridView的空白行?

你可以尝试这样的事情:

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

请告诉我它是否有帮助. =)