Telerik blogs

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.


About the Author

Nikolay Diyanov

Diyanov is the Product Manager of the Native Mobile UI division at Progress. Delivering outstanding solutions that make developers' lives easier is his passion and the biggest reward in his work. In his spare time, Nikolay enjoys travelling around the world, hiking, sun-bathing and kite-surfing.

Find him on Twitter @n_diyanov or on LinkedIn.

Related Posts

Comments

Comments are disabled in preview mode.