This is a migrated thread and some comments may be shown as answers.

Change row font when checkbox is checked

2 Answers 110 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jerry
Top achievements
Rank 1
jerry asked on 14 May 2009, 03:08 PM

I currently have a grid with a checkbox column.  When the user checks the checkbox I change the background color and that works fine but i'm unable to change the text color on the ValueChanged event of that grid.

//Row Highlight when selected  
GridCheckBoxCellElement cbCell = (GridCheckBoxCellElement)sender;  
cbCell.RowElement.BackColor = System.Drawing.ColorTranslator.FromHtml("#DAFB5E");  
cbCell.RowElement.DrawFill = true;  
cbCell.RowElement.ForeColor = this.radGVTables.ForeColor = Color.Sienna;  
 
//I've tried this and it didn't work either.  
cbCell.RowElement.ForeColor = Color.Sienna; 


Thank you for any help



 

 

 

 

2 Answers, 1 is accepted

Sort by
0
gerbrand
Top achievements
Rank 2
answered on 14 May 2009, 09:07 PM
Hi Jerry,

I made a small change on your sample code that should do the trick.

//Row Highlight when selected   
GridCheckBoxCellElement cbCell = (GridCheckBoxCellElement)sender;   
cbCell.RowElement.BackColor = System.Drawing.ColorTranslator.FromHtml("#DAFB5E");   
cbCell.RowElement.DrawFill = true;   
//cbCell.RowElement.ForeColor = this.radGVTables.ForeColor = Color.Sienna;   
 
//I think you have to specify it foreach column in your grid that you need to change the color. Maybe there is a better way, didn't find it. 
cbCell.RowInfo.Cells["columnname"].CellElement.ForeColor = Color.Sienna; 
  
//I've tried this and it didn't work either.   
//cbCell.RowElement.ForeColor = Color.Sienna;  

Hope it helps you to a solution.

I added it to my sample application on my weblog also.

Gerbrand




0
Jack
Telerik team
answered on 15 May 2009, 07:32 AM
Hi jerry,

RadGridView uses virtualization for its visual elements. They are reused when scrolling or changing the grid content. The only safe place, where you can change the background color of some cell is the CellFormatting event (ViewCellFormatting respectively). These events are fired also when the cell changes its value. So, you should move your logic inside the CellFormatting event.

If you need further assistance, please write us back.

Regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
jerry
Top achievements
Rank 1
Answers by
gerbrand
Top achievements
Rank 2
Jack
Telerik team
Share this question
or