Change row font when checkbox is checked

3 posts, 0 answers
  1. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 14 May 2009 Link to this post

    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. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 14 May 2009 Link to this post

    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




  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 15 May 2009 Link to this post

    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.
Back to Top