We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

datagrid alternating rows

Thread ID:

Created:

Updated:

Platform:

Replies:

113936 Oct 17,2013 05:02 PM UTC Oct 22,2013 06:48 AM UTC WinRT 5
loading
Tags: SfDataGrid
Jacob Bohrtz
Asked On October 17, 2013 05:02 PM UTC

I would like to have a datagrid with alternating rows.  I have tried to use the example and can't get it to work.

Datagrid in xaml:

<Grid:SfDataGrid x:Name="gridLDQ" AutoGenerateColumns="False" 
                                            HeaderStyle="{StaticResource headerStyle}" AllowGrouping="False" AllowResizingColumns="False" AutoExpandGroups="False" DetailsViewPadding="0" 
                                            NavigationMode="Row" AllowSorting="False" BorderThickness="0" CurrentCellBorderThickness="0" CurrentCellBorderBrush="#00FFFFFF"
                                            RowStyleSelector="{StaticResource rowStyleSelector}" CellStyle="{StaticResource cellStyle}">
                                        <Grid:SfDataGrid.Columns>
                                            <Grid:GridTextColumn MappingName="Reqnum" HeaderText="Req #" Width="80"/>
                                            <Grid:GridTextColumn MappingName="Ternum" HeaderText="Ter #" Width="60"/>
                                            <Grid:GridTextColumn MappingName="Customer" HeaderText="Customer" Width="280"/>
                                            <Grid:GridTextColumn MappingName="BU" HeaderText="BU" Width="60"/>
                                            <Grid:GridTextColumn MappingName="ReqDesc" HeaderText="Description" Width="280"/>
                                        </Grid:SfDataGrid.Columns>
                                    </Grid:SfDataGrid>


Added this in page.resources

<local:CustomRowStyleSelector x:Key="rowStyleSelector" />

Added the class (in vb)

Public Class CustomRowStyleSelector
    Inherits StyleSelector

    Protected Overrides Function SelectStyleCore(item As Object, container As DependencyObject) As Style
        Return MyBase.SelectStyleCore(item, container)
        If item.RowIndex Mod 2 = 0 Then
            Return App.Current.Resources("altrowStyle")
        Else
            Return App.Current.Resources("rowStyle")
        End If
    End Function

End Class


My styles in app.xaml

<Style x:Key="rowStyle" TargetType="Grid:VirtualizingCellsControl">
                <Setter Property="Background" Value="#7380a605"/>
                <Setter Property="Padding" Value="0"/>
            </Style>

            <Style x:Key="altrowStyle" TargetType="Grid:VirtualizingCellsControl">
                <Setter Property="Background" Value="#3A80a605"/>
                <Setter Property="Padding" Value="0"/>
            </Style>

            <Style x:Key="cellStyle" TargetType="Grid:GridCell">
                <Setter Property="FontFamily" Value="Segoe UI"/>
                <Setter Property="FontSize" Value="13"/>
                <Setter Property="Foreground" Value="#FFEFEFEF"/>
                <Setter Property="Padding" Value="0"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>

            <Style x:Key="headerStyle" TargetType="Grid:GridHeaderCellControl">
                <Setter Property="Foreground" Value="#FF80a605"/>
                <Setter Property="FontFamily" Value="Segoe UI"/>
                <Setter Property="FontSize" Value="14"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="HorizontalAlignment" Value="Left"/>
            </Style>


It doesn't go into the function to change the row styles.  Is it because I do not set the itemssource in xaml, instead later in code?

Jai Ganesh S [Syncfusion]
Replied On October 18, 2013 10:28 AM UTC

Hi Jacob,

 

Thanks for using Syncfusion products.

 

We have analyzed your query with our sample. We are unable to reproduce the issue. Can you please revert us by modifying the sample based on your application along with the replication procedure. This would be helpful for us to serve you.

 

Sample: GridRowSelectionSample.zip

 

Note: We have tested the reported issue in version 11.3.0.32.

 

Please let us know if you need further assistance.

 

Thank you,

Jai Ganesh S


Jacob Bohrtz
Replied On October 18, 2013 05:35 PM UTC

Your example works...thanks.  I'm still not able to get it to work in my VB code, when I update the Itemssource on the datagrid it does not enter in the CustomRowStyleSelector code class, is there a way trigger that?

Jai Ganesh S [Syncfusion]
Replied On October 21, 2013 12:25 PM UTC

Hi Jacob,

 

Thanks for your update.

 

We have tested the reported issue in vb. We are unable to reproduce the issue. Can you please revert us by modifying the sample based on your application along with the replication procedure. This would be helpful for us to serve you.

 

Sample: GridRowStyle VB_Project.zip

 

Please let us know if you need further assistance.

 

Thank you,

Jai Ganesh S


Jacob Bohrtz
Replied On October 21, 2013 01:05 PM UTC

Thanks for your help, I got mine to work!

As soon as I copied your class, I noticed a few differences and it worked immediately.  Don't quite know why yet but thanks.

Jai Ganesh S [Syncfusion]
Replied On October 22, 2013 06:48 AM UTC

Hi Jacob,

 

Thanks for your update.

 

Please let us know if you need further assistance.

 

Thank you,

Jai Ganesh S


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;