繁体   English   中英

颜色datagridview单元格及其旁边的一个根据条件

[英]color datagridview cell and the one next to it based on condition

我下面的代码仅根据文本值更改1个单元格的颜色。 如何根据相同的值更改单元格和下一列中单元格的颜色。 谢谢

Private Sub DataGridView1_CellFormatting1(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting


     If Not DataGridView1.Rows(e.RowIndex).IsNewRow Then
        If e.ColumnIndex = DataGridView1.Columns("Dept1").Index Then
            If Not IsDBNull(e.Value) Then
                If e.Value = "Staring" Then
                    e.CellStyle.BackColor = Color.LightGray

                    e.CellStyle.Font = New Font("Arial", 16.0F)


                End If
            End If
        End If
    End If
End Sub

你有尝试过吗?

DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex + 1)

就像是:

If Not DataGridView1.Rows(e.RowIndex).IsNewRow Then
  If e.ColumnIndex = DataGridView1.Columns("Dept1").Index Then
    If Not IsDBNull(e.Value) Then
      If e.Value = "Staring" Then
        e.CellStyle.BackColor = Color.LightGray
        e.CellStyle.Font = New Font("Arial", 16.0F)

        Dim otherCell As DataGridViewCell =
          DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex + 1)

        otherCell.Style.BackColor = e.CellStyle.BackColor
      End If
    End If
  End If
End If

参考文献:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM