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

How to cell HeaderCellStyle for Columns of a grid with AutoGenerateColumns=true?

5 Answers 167 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Abhay
Top achievements
Rank 1
Abhay asked on 13 Jan 2012, 06:22 AM
Hello,

I have a grid with AutogenerateColumns=true and all it's columns are generated dynamically. I want to set HeaderCellStyle property for it's columns. Please suggest a solution.

Thanks,
Abhay Gupta

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 13 Jan 2012, 06:24 AM
Hello,

You can define the style as an implicit one, thus applying it for all the columns. If you want to set it only to some particular ones, you can handle AutoGeneratingColumn event and assign the style defined in xaml to the HeaderCellStyle of the column.
 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Abhay
Top achievements
Rank 1
answered on 13 Jan 2012, 06:44 AM
Implicit one???? I didnt get your point. Could you please suggest me a demo or something
0
Abhay
Top achievements
Rank 1
answered on 13 Jan 2012, 08:34 AM
reply please!!!!!
0
Pascal
Top achievements
Rank 1
answered on 01 Mar 2012, 11:32 AM
Can you please reply?


0
Accepted
Maya
Telerik team
answered on 01 Mar 2012, 12:33 PM
Hello Pascal,

You can define an implicit style that will be applied to all header cells:

<UserControl.Resources>    
   <Style TargetType="telerik:GridViewHeaderCell">
       <Setter Property="Background" Value="SpringGreen" />
   </Style>
</UserControl.Resources>

The other possible approach would be to set it explicitly during AutoGeneratingColumn:
//XAML:
 <UserControl.Resources>   
        <Style x:Key="MyHeaderCellStyle" TargetType="telerik:GridViewHeaderCell">
            <Setter Property="Background" Value="SpringGreen" />
        </Style>
    </UserControl.Resources>
 
//C#:
    private void clubsGrid_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
        {
            e.Column.HeaderCellStyle = (Style)this.Resources["MyHeaderCellStyle"];
        }

 

All the best,
Maya
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Abhay
Top achievements
Rank 1
Answers by
Maya
Telerik team
Abhay
Top achievements
Rank 1
Pascal
Top achievements
Rank 1
Share this question
or