Articles in this section
Category / Section

How to change the column stacking at runtime in StackedHeader of WinRT DataGrid?

1 min read

You can define more than one header for SfDataGrid using SfDataGrid.StackedHeaderRows and you can define the columns by setting StackedHeaderRows.StackedColumns. The columns in StackedHeaderRow are stacked or grouped based on the StackedColumn.ChildColumns property. The following code example has SfDataGrid defined with StackedHeaderRows.

XAML

<Syncfusion:SfDataGrid Name="SfdataGrid" 
                       AutoGenerateColumns="True"
                       ItemsSource="{Binding Employee}">
    <Syncfusion:SfDataGrid.StackedHeaderRows>
        <Syncfusion:StackedHeaderRow>
            <Syncfusion:StackedHeaderRow.StackedColumns>
                <Syncfusion:StackedColumn ChildColumns="EmployeeID,Name" HeaderText="Employee Details"/>
                <Syncfusion:StackedColumn ChildColumns="ContactID,Title" HeaderText="Contact details"/>
                <Syncfusion:StackedColumn ChildColumns="SickLeaveHours,Salary" HeaderText="Salary Details"/>
            </Syncfusion:StackedHeaderRow.StackedColumns>
        </Syncfusion:StackedHeaderRow>
    </Syncfusion:SfDataGrid.StackedHeaderRows>
</Syncfusion:SfDataGrid>

The following screenshot shows SfDataGrid with StackedHeaderRows.

stacked header rows in SfDataGrid

Figure 1: SfDataGrid with StackedHeaderRows

You can change the column stacking at runtime by setting the StackedColumns.ChildColumns property as shown in the following code example.

C#

private void AddinStackedHeaderRow_Click(object sender, RoutedEventArgs e)
{
    var childcolumn = this.SfdataGrid.StackedHeaderRows[0].StackedColumns[0].ChildColumns;
    this.SfdataGrid.StackedHeaderRows[0].StackedColumns[0].ChildColumns = childcolumn + "," + "BirthDate" + "," + "NationalIDNumber";
}

The following screenshot shows the output of the SfDataGrid with the newly updated ChildColumns to the already existing StackedColumn in StackedHeaderRows.

child columns in SfDataGrid

Figure 2: ChildColumns added to the existing StackedColumn

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied