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

GridViewDataColumn "Style"

1 Answer 203 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 14 Jan 2013, 12:28 PM
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.

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 14 Jan 2013, 01:34 PM
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.

Tags
GridView
Asked by
Mike
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or