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

Alternating color of rows

8 Answers 488 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 25 Mar 2009, 09:24 PM
Hi!

There is any way to show a different color for even and odd rows?

Thanks!

8 Answers, 1 is accepted

Sort by
0
Sid
Top achievements
Rank 1
answered on 26 Mar 2009, 04:42 AM
John,

The easiest way is to apply a theme.  The Telerik theme has alternating row colors.  You can set this individually in the property for the grid or you can make it app wide by placing a style in the app.xaml file.  (This assumes you're using the 2009Q1 version, the property is StyleManager.Theme vs. Theming.Theme)

 

 

 

 

            <Style TargetType="{x:Type telerik:RadGridView}">  
                <Setter Property="telerik:StyleManager.Theme">  
                    <Setter.Value>  
                        <telerik:TelerikTheme/>  
                    </Setter.Value>   
                </Setter>   
            </Style> 

 

 

 

 

HTH,
-Sid.

 

 

0
John
Top achievements
Rank 1
answered on 26 Mar 2009, 07:27 AM
Hi!

All my application are currently using the Vista theme, and in this Theme the rows are all of the same color.  I'm happy with this theme so it's in consonance with the app.

Can I make it without changing the general look of the gridview?


Thanks
0
Accepted
Kalin Milanov
Telerik team
answered on 26 Mar 2009, 12:32 PM
Hi John,

Here is a sample code which shows how to set background color to alternate grid rows. This one again assumes you have 2009Q1 version of the RadGridView.

<telerik:RadGridView Name="RadGridView1" telerik:StyleManager.Theme="Vista"
<telerik:RadGridView.Resources> 
         <Style x:Key="GridViewAlternateRowStyle" TargetType="telerik:GridViewRow"
                 <Setter Property="Background" Value="Red" /> 
                </Style> 
        </telerik:RadGridView.Resources> 
        <telerik:RadGridView.RowAppearance> 
         <telerik:RowAppearanceSettings UseAlternateRowStyle="True" 
AlternateRowStyle="{StaticResource GridViewAlternateRowStyle}" /> 
</telerik:RadGridView.RowAppearance> 
</telerik:RadGridView> 

I guess you would also want to replace the Red color with the one of your choice.

Sincerely yours,
Kalin Milanov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Brad
Top achievements
Rank 1
answered on 20 Apr 2009, 09:21 PM
How do you keep the column lines?
0
Kalin Milanov
Telerik team
answered on 22 Apr 2009, 05:39 AM
Hi Brad,

I do not understand your concern. Could you please elaborate on your issue with the column lines? 
Currently Vista theme displays vertical grid lines and they are shown even if you recolor you rows or use alternate row colors. 

I am waiting for more information. 

Sincerely yours,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
0
Rodney Foley
Top achievements
Rank 1
answered on 19 Nov 2009, 08:20 PM
Kalin ,

If that is for 2009Q1 what is the solution for 2009Q3?

I have the same need and it seems by your comments that I shouldn't try your example on anything but 2009Q1.  If it is for 2009Q1 or HIGHER then that would be great. 
0
Kalin Milanov
Telerik team
answered on 20 Nov 2009, 03:43 PM
Hi Rodney,

The solution for Q3 is pretty much the same. Here is some sample XAML:
<Window.Resources>
    <Style x:Key="AlternateRowColor" TargetType="{x:Type telerik:GridViewRow}">
        <Setter Property="Background" Value="Red" />
    </Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
    <telerik:RadGridView ItemsSource="{Binding Collection, Source={StaticResource SampleDataSource}}" AlternationCount="2" AlternateRowStyle="{DynamicResource AlternateRowColor}"/>
</Grid>

I hope this helps.

Regards,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Rodney Foley
Top achievements
Rank 1
answered on 20 Nov 2009, 04:04 PM
Thanks, and for the record that is not pretty much the same, they are different enough that the first example didn't work and the second one does. :)  Since telerik:RowAppearanceSettings doesn't exist any more and the AlternateRowStyle is now a RadGridView property. Yeah but working and not working are pretty much the same. :)
Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
Sid
Top achievements
Rank 1
John
Top achievements
Rank 1
Kalin Milanov
Telerik team
Brad
Top achievements
Rank 1
Rodney Foley
Top achievements
Rank 1
Share this question
or