Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my program i want change the color in datagridview rows or cells depending upon some conditions at runtime how to do it

I give following code
for colorchange but it is not working please help anybody
VB
DataGridView2.Rows(0).Cells(0).Style.BackColor = Color.Green

And i have change and check it using following coding but still it is not working
VB
Datagridview2.CurrentRow.DefaultCellstyle.Backcolor=Color.Green

Thank you very much in Advance
Posted
Updated 6-Jan-12 1:15am
v2

1 solution

For cells your code should work:
VB
DataGridView2.Rows(0).Cells(0).Style.BackColor = Color.Green
For rows:
VB
DataGridView2.Rows(0).DefaultCellStyle.BackColor = Color.Green
or:
VB
DataGridView2.Rows(DataGridView2.CurrentRow.Index).DefaultCellStyle.BackColor = Color.Green
 
Share this answer
 
v6
Comments
devausha 6-Jan-12 23:40pm    
But, I already try the above codings it is not working
Scubapro 7-Jan-12 11:38am    
Then you'll probably have a bounded datagridview. In that case use the above codes in the CellFormatting event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900