Styling the first column for all the grids

6 posts, 0 answers
  1. Paolo
    Paolo avatar
    423 posts
    Member since:
    Jun 2009

    Posted 09 Jan 2014 Link to this post

    Hello,
    I've some grids in a SL 5 application, I've defined a style for the first row I was wondering if it's possible to apply it to all the RadGrid I've instead of setting it as

    <telerik:GridViewDataColumn DataMemberBinding="{Binding DESCRIZIONE}"
                                           Header="{Binding Path=Resource1.DESCRIZIONE, Source={StaticResource LocalizedStrings }}"
                                           HeaderCellStyle="{StaticResource GridViewHeaderCellStyleFirst}" UniqueName="DESCRIZIONE" />

    Is this possible?
    How?

    Thanks in advance
    Paolo
  2. Hristo
    Admin
    Hristo avatar
    41 posts

    Posted 13 Jan 2014 Link to this post

    Hi Paolo,

    The first row is the header row. This row contains header cells. These row and the cells have different styles when compared to the other rows and cells  so you would have to modify them if you want to change the style.

    There are two possible approaches to your issue.
    1. To create an empty style and set it up on your own.
    2. To copy the default style of the control and modify it.
    For modifying the default style you can follow the instructions in this article.

    In order to apply a style to all elements of the same type in several gridviews you have to omit the x:Key property. This will cause the style to be applied to all items matching the TargetType. This is known as an implicit style. More information on implicit styles  can be found here: link.

    You can see following the snippet for an example of an implicit style:
    <Style TargetType="telerik:GridViewHeaderCell">
        <Setter Property="Background" Value="Green"/>
    </Style>


    Regards,
    Hristo
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Paolo
    Paolo avatar
    423 posts
    Member since:
    Jun 2009

    Posted 13 Jan 2014 Link to this post

    Hello,

    I was menaning the first column.......I need to have the fist column of a grid to be styled in a particular way....... I don't want to put a Cell style on each page...

    Thanks

  5. Hristo
    Admin
    Hristo avatar
    41 posts

    Posted 14 Jan 2014 Link to this post

    Hello Paolo,

    You can not target the first column directly, because the columns are not visual elements. Instead you can create a style targeting GridViewCell or GridViewHeaderCell depending on what you want to style. After that you would have to assign a value to the x:key property. Following this you would have to use CellStyle (HeaderCellStyle) for the column you want to style and call the static resource specified by the key. The style is located inside UserControl.Resources

    You can see the following snippet for example:
    <UserControl.Resources>
        <Style TargetType="telerik:GridViewCell" x:Key="FirstColumn">
            <Setter Property="Background" Value="Green"/>
        </Style>
    </UserControl.Resources>
     
    <!-- more xaml code here -->
      
    <telerik:RadGridView Name="playersGrid"
                  ItemsSource="{Binding Players}"
                  AutoGenerateColumns="False">
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" CellStyle="{StaticResource FirstColumn}"/>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Number}"/>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Position}"/>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Country}"/>
         </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    More information on styling the column headers can be found in our online documentation on the following link: link

    Regards,
    Hristo
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. T
    T avatar
    1 posts
    Member since:
    Aug 2014

    Posted 22 Aug 2014 in reply to Hristo Link to this post

    I think the first data column should in fact use
    HeaderCellStyle="{StaticResource FirstColumn}"

    No?
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Aug 2014 Link to this post

    Hi,

    You should apply HeaderCellStyle if you would like to style the GridViewHeaderCells. On the other hand, when you need to style the GridViewCells, then you should apply a CellStyle as my colleague suggested.

    You can also refer to the RadGridView Styles and Templates section in our documentation.

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
DevCraft banner