Solved

Alternate Row Colours in DataGridView

Posted on 2006-10-26
4
1,861 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

19 Experts available now in Live!

Get 1:1 Help Now