Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1873
  • 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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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