Articles in this section
Category / Section

How to set back initial columns order after reordering columns in WinRT DataGrid?

2 mins 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

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