Articles in this section
Category / Section

How to change the column stacking at runtime in StackedHeader of UWP 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

 

Conclusion

I hope you enjoyed learning about how to change the column stacking at runtime in StackedHeader of UWP DataGrid.

You can refer to our UWP DataGrid feature tourpage to know about its other groundbreaking feature representations and documentation, on how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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