Solved

Alternate Row Colours in DataGridView

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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