Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1875
  • Last Modified:

Alternate Row Colours in DataGridView

Hi

I use the following code fill a datagridview called dgassets on load:

    Private Sub RetrieveAssets()

        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\ITAssets.mdb")
        Dim adapter As New OleDbDataAdapter("SELECT * FROM tblAssets", conn)
        Dim dt As New DataTable("tblAssets")

        adapter.Fill(dt)

        dgAssets.DataSource = dt
       
        dgAssetsFormat()

    End Sub

How can I alternate the row colour for each record, ie grey for the 1st, white for the second and then back to grey for the 3rd.

Thanks
0
weight01
Asked:
weight01
  • 2
1 Solution
 
XeavnCommented:
Set an AlternatingItem Style for white, and an ItemStyle for Grey.

<AlternatingItemStyle Color="White"/>
<ItemStyle Color="Grey"/>
0
 
newyuppieCommented:
there is a property you can access at design time in the datagridview called AlternatingRowsDefaultCellStyle.
you can read about it at MSDN: http://msdn2.microsoft.com/en-us/library/txth0a6h.aspx
0
 
weight01Author Commented:
newyuppie - that worked fine reading that article.

Thanks, your help is appreciated.
0
 
newyuppieCommented:
thanks for the grade
NY
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now