0

Hello Friend,

i hope someone can help me to solve my problem, i already put my database on datagridview, but my boss dont want it in standard color, so now i dont now how to change it, can i change the color using datagridview or i need to use another tools like listview?

3
Contributors
4
Replies
36
Views
4 Years
Discussion Span
Last Post by Hazuan Nazri
0

Try using the BackgroundColor property. Or something like this : Mygrid.Rows(RowIndex).DefaultCellStyle.BackColor = Color.Mycolor

1

Try :

    For i As Integer = 0 To DataGridView1.RowCount - 1
        If DataGridView1.Rows(i).Index Mod 2 = 0 Then
            DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue
        Else
            DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LemonChiffon
        End If
    Next i

Edited by Jx_Man

Votes + Comments
That works, but why not use AlternatingRowsDefaultCellStyle?
1

As TnTinMN suggested. You can try AlternatingRowsDefaultCellStyle. The value for alternating rows overrides the value for all rows.

Just two lines code :

    DataGridView1.RowsDefaultCellStyle.BackColor = Color.LightBlue  'Or you can use: DataGridView1.DefaultCellStyle.BackColor = Color.LightBlue
    DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LemonChiffon

Edited by Jx_Man

Votes + Comments
Great example
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.