[英]color datagridview cell and the one next to it based on condition
my code below only change color of 1 cell based on text value. 我下面的代码仅根据文本值更改1个单元格的颜色。 How can I change color of a cell and the one on the next column based on same value. 如何根据相同的值更改单元格和下一列中单元格的颜色。 thanks 谢谢
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
Did you try this? 你有尝试过吗?
DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex + 1)
Something like: 就像是:
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
References: 参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.