如何获取datagridview.rows()。列()。样式。背面的backcolor在cellValidating中工作?
我有一个datagridview,其中我在输入时用绿色绘制绿色的细胞和白色。如果将错误捕获在单元格验证中,我需要将单元的颜色更改为红色。最后一部分IE在细胞验证中以红色绘画似乎不起作用。 这是可疑的代码:
Private Sub DataGridView4_CellValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView4.CellValidating
' check if the quantity is valid
Dim Str_Input As String = CStr(e.FormattedValue)
Dim Str_ColumnName As String = DataGridView4.Item(e.ColumnIndex, e.RowIndex).OwningColumn.Name
If Str_ColumnName = "quantity" Then
If Not (IsNumeric(Str_Input)) Then
DataGridView4.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.Red
DataGridView4.InvalidateCell(e.ColumnIndex, e.RowIndex)
e.Cancel = True
End If
End If
End Sub
I have a datagridview in which I paint in green the cell on entering and in white while endediting. I need to change the color of the cell to red if an error is trapped in cell validating. The last part i.e painting in red in cell validating seems not to work.
Here is the suspected code:
Private Sub DataGridView4_CellValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView4.CellValidating
' check if the quantity is valid
Dim Str_Input As String = CStr(e.FormattedValue)
Dim Str_ColumnName As String = DataGridView4.Item(e.ColumnIndex, e.RowIndex).OwningColumn.Name
If Str_ColumnName = "quantity" Then
If Not (IsNumeric(Str_Input)) Then
DataGridView4.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.Red
DataGridView4.InvalidateCell(e.ColumnIndex, e.RowIndex)
e.Cancel = True
End If
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论