Persist hidden columns when closing ColumnChooser?

Hi,

I like the drag and drop style of the standard provided column chooser.

When i subscribe to the closing event of the column chooser window, do i have access to the columns which were shown inside the columnchooser?
Those are the columns that the user selected as hidden and i would like to persist them, so that on the next startup they are not initially shown in the grid.

I know that i can do that using a custom column chooser, like you show in your sample, but would like to know, if this info is available in the standard.

thx,

Helmut

1 Reply

GT Gnanasownthari Thirugnanam Syncfusion Team October 23, 2017 01:26 PM UTC

Hi Helmut, 
 
Using serialization and Deserialization functionality of SfDataGrid, you can access the added columns in ColumnChooser when you start the application again. Please refer the below code snippet and you can modify this based on the requirement in your application.  
 
this.Loaded += MainWindow_Loaded; 
this.Closing += MainWindow_Closing; 
 
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) 
{ 
    using (var file = File.Create("SfDataGrid.xml")) 
    { 
        //Serialize the file. 
        this.dataGrid.Serialize(file); 
    } 
} 
 
void MainWindow_Loaded(object sender, RoutedEventArgs e) 
{ 
    try 
    { 
        using (var file = File.Open("SfDataGrid.xml", FileMode.Open)) 
        { 
            //Deserialize the file 
            dataGrid.Deserialize(file); 
        } 
    } 
        //Catch the exception for initially run the sample. 
    catch (FileNotFoundException) 
    { 
 
    }            
 
 
 
We have prepared the sample for the same, you can download it from below mentioned location. 
 
Sample location: 
 
Please refer the below UG link for more details about Serialization and Deserialization. 
 
Regards, 
Gnanasownthari T 


Loader.
Up arrow icon