Help with formating DataGridView using VB,NET

vcharles
vcharles used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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 !

Author

Commented:
Can you please send me the solution in VB.NET.

Thanks,

Victor

Author

Commented:
Which property of the Grid, should the code be included?
This page should answer most of your questions :

https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowsdefaultcellstyle%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

The code would be called from anywhere, but I guess FormLoad would be a good place to start.

Author

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial