vb.net – 如果用户单击该行并将焦点从该行移开,则重置DataGridV
发布时间:2020-12-17 07:11:11 所属栏目:百科 来源:网络整理
导读:如果用户单击DataGridView底部的空白行并将焦点从DataGridView移开,则现在单击的行处于指示对该行进行更改的状态. 是否可以告诉DataGridView取消标记该行是否被更改? 焦点离开DataGridView时是否可以重置此行? 我们使用以下事件处理程序来提醒用户,如果将I
|
如果用户单击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
看起来我们需要一种方法来阻止执行,如果用户只需单击网格然后单击表单中的其他位置. 解决方法
你可以尝试这样的事情:
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
请告诉我它是否有帮助. =) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 关于我应该什么时候应该对malloc感到困惑
- reactjs – 如何在使用webpack发布NPM模块(React组件)时正确
- Ruby的对象模型中首先出现了什么?
- objective-c – 如何使用AFNetworking立即强制取消NSOperat
- c# – 将枚举设置为其默认值
- Accessing Server-Side Data with Flex
- 《swift2.0 官方教程中文版》 第2章-12下标脚本
- Ruby:是否可以在不对类名进行硬编码的情况下确定我的Ruby方
- c# – .NET DLR和SecurityException
- ruby-on-rails – 从多个地方渲染javascript:Rails方式
