Murray Brown
asked on
Using a class to color a DataGridView
Hi
I have never used a class before but thought that it might be appropriate for what I need to do. I have 50 DataGridViews where I need to color the alternate rows using the code below. Now I assume that the first thing to do would be to add a Class module then how would I parse in the DataGridView name given that two of the same names may exist on different forms?
Thanks
Public Class Class1
Sub ColorDGV(ByVal oDataGridView As DataGridView)
Dim D As DataGridView = oDataGridView
For i As Integer = 0 To D.Rows.Count - 1
If i Mod 2 = 0 Then
D.Rows(i).DefaultCellStyle .BackColor = Color.LightGray
'D.Rows(i).DefaultCellStyl e.ForeColo r = Color.White
Else
'D.Rows(i).DefaultCellStyl e.BackColo r = Color.FromArgb(74, 74, 74)
End If
Next i
End Sub
End Class
I have never used a class before but thought that it might be appropriate for what I need to do. I have 50 DataGridViews where I need to color the alternate rows using the code below. Now I assume that the first thing to do would be to add a Class module then how would I parse in the DataGridView name given that two of the same names may exist on different forms?
Thanks
Public Class Class1
Sub ColorDGV(ByVal oDataGridView As DataGridView)
Dim D As DataGridView = oDataGridView
For i As Integer = 0 To D.Rows.Count - 1
If i Mod 2 = 0 Then
D.Rows(i).DefaultCellStyle
'D.Rows(i).DefaultCellStyl
Else
'D.Rows(i).DefaultCellStyl
End If
Next i
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks very much
The simpliest way:
MyDataGridView.RowsDefault
MyDataGridView.RowsDefault
MyDataGridView.Alternating
MyDataGridView.Alternating