Articles in this section
Category / Section

How to set back the initial columns order after reordering the columns in UWP DataGrid control?

1 min read

SfDataGrid allows you to set back the initial columns order after reordering the columns by saving the initial columns order while initializing. You can restore the initial order whenever required.

The following code example demonstrates how to restore the initial columns order in a button click.

C#

public List<GridColumn> columns;
        public MainWindow()
        {
            InitializeComponent();
           // Saving the initial columns order
            columns = dataGrid.Columns.ToList();
        } 
        
        private void RestoreButton_Click(object sender, RoutedEventArgs e)
        {
            this.dataGrid.Columns.Clear();
            // Restoring the original columns order
            foreach (GridColumn column in columns)
            {
                this.dataGrid.Columns.Add(column);
            }
        }

 

Here the initial columns order is stored in a list. When you click the Restore button, the Columns in the DataGrid is cleared by using the Clear method. Then the columns stored in the list are added back to the DataGrid.

Sample Links:

WPF

WRT

SilverLight

UWP


Conclusion

I hope you enjoyed learning about how to set back the initial columns order after reordering the columns in UWP DataGrid control.

You can refer to our UWP DataGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our UWP DataGrid documentation to understand how to create and manipulate data.

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