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

GridViewHeaderCell style with AutoGenerated Columnscolumns

8 Answers 293 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shaun
Top achievements
Rank 1
Shaun asked on 11 Nov 2011, 08:09 PM
I'm using the RadGridview with the Metro theme applied. I want to change, and only change the background color of the HeaderCell. I can do this easily if I'm defining each data column, like below:

XAML:
 <telerik:GridViewDataColumn Header="Type" Width="150" DataMemberBinding="{Binding TypeDisplay}" HeaderCellStyle ="{StaticResource raHeaderCellStyle}"/>

Style:
    <Style x:Key="raGridViewHeaderCellControlTemplate" TargetType="telerik:GridViewHeaderCell">
        <Setter Property="Background" >
            <Setter.Value>
                <SolidColorBrush Color="Blue" />
            </Setter.Value>
        </Setter>
    </Style>

However, if I AutoGenerate columns  I can't figure out how to set this cellheader style. Thanks.

8 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 11 Nov 2011, 08:22 PM
Hello Nk,

 

You may subscribe to the AutoGeneratingColumn event of RadGridView to access auto-generated columns and set the corresponding HeaderCellStyle from there.


All the best,
Vanya Pavlova
the Telerik team

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

0
Shaun
Top achievements
Rank 1
answered on 11 Nov 2011, 08:28 PM
Thanks for the quick reply!  Would you be so kind as to give me an example of the syntax for applying the style to all the headercells? Thanks.
0
Vanya Pavlova
Telerik team
answered on 11 Nov 2011, 08:48 PM
Hello Nk,

 
If you want this style to be applied to all GridViewHeaderCells you may mark this style as an implicit one and it will be applied to all elements of this type:

<Style TargetType="telerik:GridViewHeaderCell">
      <Setter Property="Background" >
          <Setter.Value>
              <SolidColorBrush Color="Blue" />
          </Setter.Value>
      </Setter>
  </Style>


You do not have to subscribe to this event for all columns. You should need to subscribe when you want to apply different header cell style for each column.

Greetings,
Vanya Pavlova
the Telerik team

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

0
Shaun
Top achievements
Rank 1
answered on 16 Nov 2011, 04:30 PM
Thanks Vanya! That was so simple. However, I tried to do the same thing for the GridViewHeaderRow, so the header cell background and the entire header row background will match but it doesn't seem to change the color. I attached the style xaml and a screenshot.  Thanks again.

Style:
    <Style TargetType="telerik:GridViewHeaderRow">
        <Setter Property="Background"  >
            <Setter.Value>
                <SolidColorBrush Color="#FFF5F5FD" />
            </Setter.Value>
        </Setter>
    </Style>

0
Vanya Pavlova
Telerik team
answered on 16 Nov 2011, 04:47 PM
Hello Nk,

 

Indeed there is a problem related to the implicit style targeted at GridViewHeaderRow in a theme different than the default one. For the time being I may suggest you to refer this style explicitly through HeaderRowStyle attribite of RadGridView:

<Window.Resources>
        <Style x:Key="style1" TargetType="telerik:GridViewHeaderRow">  
...
        <Setter Property="Background" Value="Red"/>
        </Style>
    </Window.Resources>
    <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}">
        <telerik:RadGridView HeaderRowStyle="{StaticResource style1}"  telerik:StyleManager.Theme="Metro" Margin="72,32,48,58" ItemsSource="{Binding Collection}"/>
    </Grid>
</Window>


I have logged this issue in our PITS System and you may track its progress here.
Furthermore I have already updated your Telerik points accordingly. 



All the best,
Vanya Pavlova
the Telerik team

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

0
Shaun
Top achievements
Rank 1
answered on 18 Nov 2011, 05:01 PM
Cool, that works. Much thanks for the quick help.
0
Shaun
Top achievements
Rank 1
answered on 18 Nov 2011, 05:02 PM
Cool, that works. Much thanks for the quick help.
0
Shaun
Top achievements
Rank 1
answered on 18 Nov 2011, 05:02 PM
Cool, that works. Much thanks for the quick help.
Tags
GridView
Asked by
Shaun
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Shaun
Top achievements
Rank 1
Share this question
or