GridViewDataColumn "Style"

2 posts, 0 answers
  1. Mike
    Mike avatar
    79 posts
    Member since:
    Nov 2011

    Posted 14 Jan 2013 Link to this post

    Hi, 

    Is there any way to refactor code when I have many columns inside the GridView, having the same values of parameters.

    For example: 
    ......
    <telerik:GridViewDataColumn UniqueName="al2" Background="{StaticResource FstBrush}" IsReadOnly="True" ....
    <telerik:GridViewDataColumn UniqueName="al3" Background="{StaticResource FstBrush}" IsReadOnly="True" ....
    <telerik:GridViewDataColumn UniqueName="al4" Background="{StaticResource FstBrush}" IsReadOnly="True" ....
    <telerik:GridViewDataColumn UniqueName="al5" Background="{StaticResource FstBrush}" IsReadOnly="True" ....
    <telerik:GridViewDataColumn UniqueName="al6" Background="{StaticResource FstBrush}" IsReadOnly="True" ....
    <telerik:GridViewDataColumn UniqueName="al7" Background="{StaticResource FstBrush}" IsReadOnly="True" ....
    <telerik:GridViewDataColumn UniqueName="al8" Background="{StaticResource FstBrush}" IsReadOnly="True" ....
    <telerik:GridViewDataColumn UniqueName="al9" Background="{StaticResource FstBrush}" IsReadOnly="True" ....
    ......


    to:
    <Style>
         <Setter property="IsreadOnly" value="True"/>
         <Setter property="Background" value="{StaticResource FstBrush}"/>
         .....
    </Style>
     
    ......
    <telerik:GridViewDataColumn UniqueName="al2"  ....
    <telerik:GridViewDataColumn UniqueName="al3"  ....
    <telerik:GridViewDataColumn UniqueName="al4"  ....
    <telerik:GridViewDataColumn UniqueName="al5"  ....
    <telerik:GridViewDataColumn UniqueName="al6"  ....
    <telerik:GridViewDataColumn UniqueName="al7"  ....
    <telerik:GridViewDataColumn UniqueName="al8"  ....
    <telerik:GridViewDataColumn UniqueName="al9"  ....
    ......


    Thanks.
  2. Yoan
    Admin
    Yoan avatar
    1214 posts

    Posted 14 Jan 2013 Link to this post

    Hi Radouan,

    Actually, you can set the IsReadOnly property to RadGridView, instead to its columns. However, if you want to change Column's background, you can define a style, targeting the GridViewCell. Please check the following code snippet for a reference:

    <UserControl.Resources>
        <SolidColorBrush Color="Red" x:Name="FstBrush"/>       
        <Style x:Key="MyStyle" TargetType="telerik:GridViewCell">
             <Setter Property="Background" Value="{StaticResource FstBrush}"/>           
        </Style>
     </UserControl.Resources>
    <telerik:RadGridView  Name="clubsGrid"
             ItemsSource="{Binding Clubs}"
             IsReadOnly="True">
           <telerik:RadGridView.Columns>
                 <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" CellStyle="{StaticResource MyStyle}"/>
           </telerik:RadGridView.Columns>
    </telerik:RadGridView>
                                                    


    I hope this helps.

    Regards,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top