Solved

Alternate Row Colours in DataGridView

Posted on 2006-10-26
4
1,862 Views
Last Modified: 2010-05-18
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
Comment
Question by:weight01
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Xeavn
ID: 17812745
Set an AlternatingItem Style for white, and an ItemStyle for Grey.

<AlternatingItemStyle Color="White"/>
<ItemStyle Color="Grey"/>
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 500 total points
ID: 17813939
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
 
LVL 1

Author Comment

by:weight01
ID: 17814036
newyuppie - that worked fine reading that article.

Thanks, your help is appreciated.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17814291
thanks for the grade
NY
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now