gpt4 book ai didi

vb.net - 根据单元格值的数量更改DataGridView中的行颜色

转载 作者:行者123 更新时间:2023-12-04 10:01:11 25 4
gpt4 key购买 nike

我需要更改 datagridview 中一行的颜色,但我的代码对我不起作用。
我总是收到一条错误消息,指出“名为数量的列:无法找到。参数名称:列名”

这是我的代码:

Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
For i As Integer = 0 To Me.DataGridView1.Rows.Count - 1
If Me.DataGridView1.Rows(i).Cells("Quantity:").Value < 5 Then
Me.DataGridView1.Rows(i).Cells("Quantity:").Style.ForeColor = Color.Red
End If
Next
End Sub

请帮我修复它。谢谢你。

最佳答案

这可能会有所帮助

  • 使用“RowPostPaint”事件
  • 列的名称不是列的“标题”。您必须转到 DataGridView 的属性 => 然后选择列 => 然后查找“名称”属性

  • 我从 C# ('From: http://www.dotnetpools.com/Article/ArticleDetiail/?articleId=74 )
        Private Sub dgv_EmployeeTraining_RowPostPaint(sender As Object, e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) 
    Handles dgv_EmployeeTraining.RowPostPaint

    If e.RowIndex < Me.dgv_EmployeeTraining.RowCount - 1 Then
    Dim dgvRow As DataGridViewRow = Me.dgv_EmployeeTraining.Rows(e.RowIndex)

    '<== This is the header Name
    'If CInt(dgvRow.Cells("EmployeeStatus_Training_e26").Value) <> 2 Then


    '<== But this is the name assigned to it in the properties of the control
    If CInt(dgvRow.Cells("DataGridViewTextBoxColumn15").Value.ToString) <> 2 Then

    dgvRow.DefaultCellStyle.BackColor = Color.FromArgb(236, 236, 255)

    Else
    dgvRow.DefaultCellStyle.BackColor = Color.LightPink

    End If

    End If

    End Sub

    关于vb.net - 根据单元格值的数量更改DataGridView中的行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13378538/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com