Category / Section
How to set back the initial columns order after reordering the columns in Silverlight 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: