DataGridView CellValidating [英] DataGridView CellValidating
本文介绍了DataGridView CellValidating的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Form1中使用DataGridView.如果列(6)> 2,则显示MsgBox无序".然后专注于当前单元格.如何编写此代码.我的代码是:
I'm using DataGridView in Form1. If Column(6)>2 then, Show MsgBox "Out of Order" then focus to current cell. How to write this code. My code is :
Private Sub DGV_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles DGV.CellValidating
If (e.ColumnIndex = 6) Then
If DGV.CurrentRow.Cells(6).Value > 2 Then Return
e.Cancel = True
MsgBox("Out of Order")
DGV.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = 6
End If
End Sub
推荐答案
Dopen,
根据您的描述,您可以参考以下代码.
According to your description, you can refer to the code below.
Private Sub DataGridView1_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
Dim dgv As DataGridView = CType(sender, DataGridView)
If dgv.Columns(e.ColumnIndex).Name = "Column6" AndAlso
e.FormattedValue > 2 Then
e.Cancel = True
MessageBox.Show("Out of Order")
End If
End Sub
最好的问候,
樱桃
这篇关于DataGridView CellValidating的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文