如何获取datagridview.rows()。列()。样式。背面的backcolor在cellValidating中工作?

发布于 2025-02-05 12:12:47 字数 793 浏览 3 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文