Styling Cells in RadGridView for WinForms

Wednesday, May 12, 2010 by WinForms Team | Comments 4

StyleCells

In RadGridView you have to handle the CellFormatting event when you want to customize the look and feel of grid cells. This is so because RadGridView uses UI virtualization. It creates elements only for cells that are currently visible - when scrolling they are reused. Of course, it will be much easier if we could access the cell directly and set its visual properties without an event.

In our next release (Q2 2010) this will be possible. By using the Style property you can set the desired background color or change the font size. Here is a sample:

this.radGridView1.Rows[5].Cells["Name"].Style.BackColor = Color.Red;
this.radGridView1.Rows[5].Cells["Name"].Style.Font = new Font(SystemFonts.DialogFont, FontStyle.Italic);
 

All changes set this way will have a greater priority than the theme, so if you want conditional styles, you still have to use the good old CellFormatting event.

Of course you can do the same with the row:

this.radGridView1.Rows[10].Style.DrawBorder = true;
this.radGridView1.Rows[10].Style.BorderWidth = 3;
this.radGridView1.Rows[10].Style.BorderColor = Color.Blue;
 

And, you can set the cell's read only state:

this.radGridView1.Rows[5].Cells["Value"].ReadOnly = true;

This feature is still in development, so your ideas and suggestions are more than welcome - you may as well see them implemented in the upcoming version. We will appreciate your feedback.

4 Comments

  • vitas 25 Mar 2011
    Can't do it on my grid.
    GridViewRowInfo.Style is absent at all.
  • Nikolay 01 Apr 2011
    Hi vitas,

    Initially, when we started implementing the features in question, the architecture of RadGridView included exposing a Style property at GridViewRowInfo. Later on, however, we decided that this property is not needed for the rows, so we removed it for the official Q2 2010. Please use the Style property that is exposed at GridViewCellInfo.
  • Uchechukwu 10 Feb 2012
    Please, I could not access the style property of the GridviewCellInfo. It's totally absent. I need to change the background color of a row in my gridview. Please I need your utmost assistance. Thanks and cheers
  • The WinForms team 10 Feb 2012
    Hi Uchechukwu,
    Thank you for writing. Please note that in order to be able to use the Style property of GridViewCellInfo, you should have installed Q2 2010 or a newer version of RadControls for WinForms. If you are currently using one of our latest releases, please open a new support ticket where we can continue discussing your case.

Add comment

  1. Formatting options
       
     
     
     
     
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)