在线等待,datagridview 焦点迁移,单元格着色的问题
环境:VB.NET(WINFORM)
实现功能:datagridview里面对编辑的单元格做验证功能,如果验证未通过,着色,焦点不迁移
我用了以下方法实现,可实现焦点不迁移,但是当前处于编辑状态的单元格无法上色,请各位大虾不吝赐教!!
Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
If e.ColumnIndex = 2 AndAlso e.RowIndex = 2 _
AndAlso DataGridView1.Rows(2).Cells(2).Value = "ab" Then
DataGridView1.Rows(2).Cells(2).Style.BackColor = Color.Blue
e.Cancel = True
Exit Sub
End If
End Sub