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

Retrieve Cell Font

1 Answer 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dev J
Top achievements
Rank 1
Dev J asked on 27 Jan 2010, 06:23 PM
How can I get the font object used in the gridview cells? The "Font" property of the gridview is not it -- it returns a different font than the one cell's text are drawn with.

Edit: I do know how to get the font in painting/formatting events, but that's not what I want. I want to be able to get it ahead of time (i. e., in the form "load" event) before anything is displayed to the user.

Thanks,
-DevJ

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 28 Jan 2010, 09:47 AM
Hi Dev J,

This is not a trivial task and we have not a convenient API that will return the cell font. You have to iterate through all property settings in the current style for the row element and check whether there is a selector with empty condition. I prepared a sample method that will do the job:

 

 

Font font = FindCellFont(this.radGridView1, "DataCell", "ControlDefault");
 
Font FindCellFont(RadGridView gridView, string cellClassName, string themeName)
{
    Font font = null;
 
    DefaultStyleBuilder builder = (DefaultStyleBuilder)ThemeResolutionService.GetStyleSheetBuilder(
        gridView, typeof(GridDataRowElement).FullName, string.Empty, themeName) as DefaultStyleBuilder;
 
    StyleSheet styleSheet = builder.Style;
 
    foreach (PropertySettingGroup group in styleSheet.PropertySettingGroups)
    {
        ClassSelector selector = group.Selectors[0] as ClassSelector;
        if (selector != null && selector.ElementClass == cellClassName && selector.Condition == null)
        {
            foreach (PropertySetting setting in group.PropertySettings)
            {
                if (setting.Property == RadItem.FontProperty)
                {
                    font = (Font)setting.Value;
                    break;
                }
            }
        }
    }
 
    return font;
}

 

We plan to improve our API to make this task simpler.

Kind regards,
Jack
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Dev J
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or