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

6 posts, 1 answers
  1. Abhay
    Abhay avatar
    22 posts
    Member since:
    Dec 2011

    Posted 13 Jan 2012 Link to this post

    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
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 13 Jan 2012 Link to this post

    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 >>

  3. Abhay
    Abhay avatar
    22 posts
    Member since:
    Dec 2011

    Posted 13 Jan 2012 Link to this post

    Implicit one???? I didnt get your point. Could you please suggest me a demo or something
  4. Abhay
    Abhay avatar
    22 posts
    Member since:
    Dec 2011

    Posted 13 Jan 2012 Link to this post

    reply please!!!!!
  5. Pascal
    Pascal avatar
    4 posts
    Member since:
    Mar 2011

    Posted 01 Mar 2012 Link to this post

    Can you please reply?


  6. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 Mar 2012 Link to this post

    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 >>
Back to Top