Avatar of vcharles
vcharles
 asked on

Help with alternating Background color of rows and columns of DataGridView that comes with VS2010

Hi,

How do you alternate the backgroud color of rows and columns in a datagriview?

Thanks,

Victor
.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
vcharles

8/22/2022 - Mon
SOLUTION
UnifiedIS

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
vcharles

ASKER
Thanks, I noticed there isn't a property for columns. How do you specify the backgroumd and forecolor of a specific column?
ASKER CERTIFIED SOLUTION
John (Yiannis) Toutountzoglou

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
John (Yiannis) Toutountzoglou

Also you can change the backColor and the foreColor of a specific Cell in a specific coloumn according to its Value..with the Cell Foratting Event...
 Private Sub DataGridView1_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
        If e.ColumnIndex = 3 Then
            If e.Value = "aaa" Then
                e.CellStyle.BackColor = Color.Green
                e.CellStyle.ForeColor = Color.Red
            End If
        End If
    End Sub

Open in new window



Yiannis
vcharles

ASKER
It Works!

Thanks,

Victor
Your help has saved me hundreds of hours of internet surfing.
fblack61
vcharles

ASKER
Thank you for the extra information.
vcharles

ASKER
Thank You for both solutions.