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.
Unfortunately, activation email could not send to your email. Please try again.

Unable to find the TableSummaryRow index in SfDataGrid's TableSummaryRows for style customisation

Thread ID:

Created:

Updated:

Platform:

Replies:

119420 Jun 18,2015 05:12 AM Jun 22,2015 03:02 AM WPF 3
loading
Tags: SfDataGrid
Anas El Hallabi
Asked On June 18, 2015 05:12 AM

Hello,

I'm trying to apply a different style on the last TableSummaryRow. For that, I used the TableSummaryRowStyleSelector="{StaticResource tableSummaryRowStyleSelector}"  property on the SfDataGrid. 
In the "SelectStyle(object item, DependencyObject container)" method in my style selector class, I am unable to get the information about the row position of the current row in SfDataGrid's TableSummaryRows: container is a Syncfusion.UI.Xaml.Grid.TableSummaryRowControl and item is a Syncfusion.UI.Xaml.Grid.SpannedDataRow

Is there a way to get that info ?

Many Thanks,
Anas

Farjana Parveen Ayubb [Syncfusion]
Replied On June 19, 2015 07:32 AM

Hi Anas,


Thank you for contacting Syncfusion support.


We analyzed your query and you can achieve your requirement “Customize the TableSummaryRowStyle based on the TableSummary row index” by getting the row index from the SpannedDataRow in StyleSeletor.


Please refer the code example and sample in the following location:


Code Snippet (XAML):


  <syncfusion:SfDataGrid x:Name="sfdatagrid" 

                               AllowEditing="True"

                               AutoGenerateColumns="False"

                               TableSummaryRowStyleSelector="{StaticResource tableSummaryStyleSelector}"
                               ItemsSource="{Binding Path=Products}" >


Code Snippet(C# - StyleSelector):


class TableSummaryStyleSelector : StyleSelector

    {

        public override Style SelectStyle(object item, DependencyObject container)

        {

            var data = item as SpannedDataRow;

            var index = data.RowIndex;

            if (index == 1)

                return App.Current.Resources["TableSummaryStyle1"] as Style;

            return App.Current.Resources["TableSummaryStyle2"] as Style;

        }
    }


Sample Location: TableSummaryRowStyle


If your requirement is differ from this could you please share the exact requirement that will help us to provide the solution in better way.


Regards,

Farjana Parveen A


Anas El Hallabi
Replied On June 19, 2015 07:56 AM

Hello Farjana Parveen A,

Thanks you for your answer.
Actually, I was aware of the RowIndex property of the spannedDataRow but in my situation, i don't know how many TableSummaryRows are actually beeing displayed in the sfdatagrid.
Thanks to debugger, i noticed that SpannedDataRow had an internal property "DataGrid" which refer to the grid. Using reflexion i managed to get it and so, the TableSummaryRows property as in code below:

var dataGrid = typeof(SpannedDataRow).GetProperty("DataGrid", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(tItem) as SfDataGrid;

var currentSummaryRow = (tItem.RowData as Syncfusion.Data.SummaryRecordEntry).SummaryRow as GridTableSummaryRow;

if (dataGrid != null && dataGrid.TableSummaryRows.Any() && dataGrid.TableSummaryRows.Last() == currentSummaryRow)
        isTheLastDisplayedRow = true;

This made the trick, thank you again for your support.

Anas

Saranya CJ [Syncfusion]
Replied On June 22, 2015 03:02 AM

Hi Anas,
Thank you for your update. Please let us know if you require any other assistance.
Regards,
Saranya

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.

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.

;