Avatar of vcharles
vcharles
 asked on

Help with formating DataGridView using VB,NET

Hi,

How do you  change a DataGridView's column's background and textcolor (Red and White) if the entire column is blank using VB.NET?

Thanks,

Victor
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
vcharles

8/22/2022 - Mon
Sylvain Drapeau

Hello !

int RowIndex = 0;
this.dataGridView1.Rows[ RowIndex ].DefaultCellStyle.BackColor = Color.Red
this.dataGridView1.Rows[ RowIndex ].DefaultCellStyle.ForeColor = Color.White
;

Open in new window


Please confirm if this works as you wish.

Thanks !
vcharles

ASKER
Can you please send me the solution in VB.NET.

Thanks,

Victor
vcharles

ASKER
Which property of the Grid, should the code be included?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Sylvain Drapeau

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
Hi,

Thanks for the link.

How do I modify the code below to also change the text color (red) of the column headears if the all the rows in the column are blank?
For i = 0 To Me.C1Screen1.Rows.Count - 1
            For j = 1 To Me.C1Screen1.Columns.Count - 1
                 If Me.C1Screen1.Rows(i).Cells(j).Value = "" Then 
                    Me.C1Screen1.Rows(i).Cells(j).Style.BackColor = Color.Red
                 End If
            Next
        Next

Open in new window


Victor