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.

Modifying Stacked Headers programatically - changes not reflected for new columns

Thread ID:

Created:

Updated:

Platform:

Replies:

119737 Jul 27,2015 11:01 AM Jul 30,2015 05:53 AM WPF 3
loading
Tags: SfDataGrid
Stebay
Asked On July 27, 2015 11:01 AM

I can successfully modify an existing Stacked Header column.

However if I add a new Stacked Header column in code, the changes are not visible.

eg:

View Model - initialise GridData property:

            List<object> data = new List<object>();

            data.Add(new TestDataRow()

            {

                HowMany = 2,

                Name = "Chickens",

                When = new DateTime(2014, 4, 16)

            });

            data.Add(new TestDataRow()

            {

                HowMany = 5,

                Name = "Ducks",

                When = new DateTime(2015, 3, 12)

            });

            GridData = new ObservableCollection<object>(data);


View - sfDataGrid:

            <syncfusion:SfDataGrid x:Name="DataGrid"
                Grid.Column="0" Grid.Row="0" ItemsSource="{Binding GridData}"
            AutoGenerateColumns="True"  AllowResizingColumns="True"
                               AllowEditing="False"
                               SelectionUnit="Row" IsEnabled="{Binding IsNotLoading}">
                <syncfusion:SfDataGrid.StackedHeaderRows>
                    <syncfusion:StackedHeaderRow>
                        <syncfusion:StackedHeaderRow.StackedColumns>
                            <syncfusion:StackedColumn  HeaderText="ONE" ChildColumns="Name"/>
                        </syncfusion:StackedHeaderRow.StackedColumns>
                    </syncfusion:StackedHeaderRow>
                </syncfusion:SfDataGrid.StackedHeaderRows>
            </syncfusion:SfDataGrid>


Code-behind - modify stacked header (click, on a test button):

            var childColToAdd = new StackedColumn();
            this.DataGrid.StackedHeaderRows[0].StackedColumns.Add(childColToAdd);
            var childCol = this.DataGrid.StackedHeaderRows[0].StackedColumns[0].ChildColumns;
            // modify first
            this.DataGrid.StackedHeaderRows[0].StackedColumns[0].ChildColumns = childCol + ",When";
            // modify second - added above - this does not work
            this.DataGrid.StackedHeaderRows[0].StackedColumns[1].ChildColumns = "qty";

The first modification does work - the second does not - BUT if I click on the qty column, in the middle, it changes the sort order - correctly.  If I then click above the text "qty" it does not change the sort order, as if the stacked column has been added but can't be seen.



Jai Ganesh S [Syncfusion]
Replied On July 28, 2015 11:01 PM

Hi Stephen,

Thank you for using Syncfusion products.

We have analyzed your query with your code snippet. In that you have modified the existing stacked header row by add the column name that is in underlying collection. Hence it worked properly but at second you gave the column name “qty” and it is not in the underlying collection. Hence it not worked. In SfDataGrid every operations (Sorting, Filtering, Grouping etc..) are worked based on the MapingName that is in the underlying collection. So could you please give the stacked column name as in the underlying collection in your application.

Please let us know if you need further assistance.

Thank you,
Jai Ganesh S

Stebay
Replied On July 30, 2015 05:36 AM

Hi Jai Ganesh S

I've found the source of my issue - the column I was adding the Stacked Header for was named HowMany, but the entity also had an attribute specifying the display name:
            [Display(Name = "qty")]
            public int HowMany { get; set; }

I was assuming the column name would therefore be "qty" but I see that the grid uses the original entity property name as the column name, but does use the Display - Name attribute for the header text.

So this is all working fine for me, thank you.

Regards
Steve

Jayapradha S [Syncfusion]
Replied On July 30, 2015 05:53 AM

Hi Steve,

We are glad to know that your issue has been resolved.

Please let us know if you have any other queries.

Regards,
Jayapradha

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.

;