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

How To Dynamically Set Font On GridViewHeaderCell?

4 Answers 158 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Albert
Top achievements
Rank 1
Albert asked on 09 Apr 2013, 07:34 PM
I have a RadGridView populated with data. I have some input controls that allow the user to change the font of the text in the header rows. I tried the following in the code-behind, but it did not work. What is the correct way to do this?

System.Windows.Style headerStyle = new Style();
headerStyle.BasedOn = reportGrid.Columns[0].HeaderCellStyle;
headerStyle.TargetType = typeof(GridViewHeaderCell);
headerStyle.Setters.Add(new Setter(GridViewHeaderCell.FontSizeProperty, 25));
reportGrid.Columns[0].HeaderCellStyle = headerStyle;

Kind Regards,
Albert

4 Answers, 1 is accepted

Sort by
0
Stephan
Top achievements
Rank 1
answered on 10 Apr 2013, 02:57 PM
Hello 
I need to do the same. I have done it with an attached property which adds a contextmenu to this grid.
With this it is possible to change the font of the header over this context menu.
A font picker I do not have at the moment but the changing works if I do it in code:


_localRadGridTableStyle = new Style(typeof(GridViewHeaderCell));       
_localRadGridHeaderStyle.Setters.Add(new Setter        
   {             
Property = GridViewHeaderCell.FontFamilyProperty,      
       Value = _headerFontInfo.Family        
   });
.... some other setters...
this.grid.Resources.Add(typeof(GridViewHeaderCell), _localRadGridTableStyle);

It works, but I don't know if this is a good solution. I'm searching for a solution to save this new
style at closing of this grid and load saved style again next time...
Which FontPicker do you take?
0
Dimitrina
Telerik team
answered on 12 Apr 2013, 02:31 PM
Hello,

You can set the Style like so:

headerStyle.TargetType = typeof(GridViewHeaderCell);
double value = 25;
headerStyle.Setters.Add(new Setter(GridViewHeaderCell.FontSizeProperty, value));
clubsGrid.Columns["Name"].HeaderCellStyle = headerStyle;

I hope this helps.
 

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Albert
Top achievements
Rank 1
answered on 15 Apr 2013, 02:44 PM
Thanks for the reply, Didie. Could you, please, upload a sample project that demonstrates this code?

Kind Regards,
Albert
0
Dimitrina
Telerik team
answered on 16 Apr 2013, 06:41 AM
Hello,

I have attached a sample project. You can now check how it works at your side.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Albert
Top achievements
Rank 1
Answers by
Stephan
Top achievements
Rank 1
Dimitrina
Telerik team
Albert
Top achievements
Rank 1
Share this question
or