DannyBoy DannyBoy - 2 years ago 85
Vb.net Question

How do I Color The background of multiple cells in one line of code?

I have a gridview that I color specific cells backgrounds.

I have a row that has 16 columns and I want to color the first 14 cells.

Can I do this with one line of code for all 14 cells?

I currently color each cell like this:

row.Cells(0).BackColor = Drawing.Color.LightGray
row.cells(1).BackColor = Drawing.Color.LightGray
row.cells(2).BackColor = Drawing.Color.LightGray

I want to be able to have one line of code that colors cells 0 through 14 all at one time. Thanks

Answer Source

Are you sure you want one line?

For i = 0 to 13 : row.Cells(i).BackColor = Drawing.Color.LightGray : Next
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download