因此,我需要每隔 4 行交替一次,而不是每隔一行交替一次。所以1-4是蓝色的,5-8是白色的。我尝试使用 mod ,rowindex
但我一直在搞砸并且没有找到正确的方法,然后我注意到网格拉入的数据有一个每 4 行具有相同数字的列。所以我在想我可以比较那个值,当它改变时,我知道我必须改变配色方案,然后再换 3 行然后切换回来。下面是使用的代码和屏幕截图示例。它只会给整个网格涂上一种颜色。
Private Sub BTFDataGrid_RowPrePaint(sender As Object, e As DataGridViewRowPrePaintEventArgs) Handles BTFDataGrid.RowPrePaint
Dim i, ReelNum,Count As Integer
ReelNum = BTFDataGrid.Rows(0).Cells("ReelNumber").Value
For i = 1 To BTFDataGrid.Rows.Count-1
If ReelNum = BTFDataGrid.Rows(e.Rowindex).Cells("ReelNumber").Value Then
BTFDataGrid.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.LightBlue
Else
BTFDataGrid.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.WhiteSmoke
Count = Count + 1
If Count = 4 Then
ReelNum = BTFDataGrid.Rows(e.RowIndex).Cells("ReelNumber").Value
Count = 0
End If
End If
Next
' This is using index
'Dim dgv = DirectCast(sender, DataGridView)
'Dim colorIndex As Integer = If((e.RowIndex / rowStep) Mod 2 = 0, 0, 1)
'dgv.Rows(e.RowIndex).DefaultCellStyle.BackColor = rowColors(colorIndex)
'For Each row As DataGridViewRow In BTFDataGrid.Rows
' Dim colorIndex As Integer = If((row.Index / rowStep) Mod 2 = 0, 0, 1)
' BTFDataGrid.Rows(row.Index).DefaultCellStyle.BackColor = rowColors(colorIndex)
'Next
End Sub