Click here to Skip to main content
15,907,913 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a grid bound to data source with one of the column status as either true or false.after loading grid I want to allow user to pick a color and and differentiate rows with status as true i.e color all rows with status as true with the selected color.

What I have tried:

I have tried using RowCellStyle event.but it applies color format on load.
Posted
Updated 22-Mar-16 21:26pm
Comments
FARONO 22-Mar-16 8:01am    
Do you mean like in Excel, Conditional formatting?
Aaliya Anwari 22-Mar-16 8:07am    
Yes
FARONO 22-Mar-16 8:13am    
Can't you set the rowstyle on a "confirm" button click? set a const with the "selected row color", and assign it to the "selected rows"?
Aaliya Anwari 22-Mar-16 8:22am    
yes i can try this.Thanks
VR Karthikeyan 22-Mar-16 8:24am    
Have you tried anything? Just show your code.

1 solution

Use CellFormatting event.

Do something like this:
C#
private void CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
    if (e.ColumnIndex = 0) {
        dgv.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.LightSkyBlue;
        dgv.Rows(e.RowIndex).DefaultCellStyle.SelectionBackColor = Color.SkyBlue;
    }
}


NOTE: you just need to format row style in one column, no need to repeat row formatting for each cell - if you need to format specific cell, ask for that particular column and format only that one (you need to add .Cells(e.ColumnIndex) after (e.rowindex).
 
Share this answer
 
v2

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