We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

FieldChooser and saving new layout of selected columns

Hi!

Is it possible to save new layout of visible columns after using FieldChooser?
I want next time when user loads form to show only columns that he previously have been selected.

1 Reply

AR Arulpriya Ramalingam Syncfusion Team June 19, 2017 09:30 AM UTC

Hi Josip, 

Thanks for using Syncfusion products. 

Query 
Response 
Is it possible to save new layout of visible columns after using FieldChooser?  
I want next time when user loads form to show only columns that he previously have been selected. 
Suggestion 1 
The GridGroupingControl does not have the direct support to maintain the previous visible columns when loading the Form. In order to save the Visible Columns and use it while loading the Form, Serialization and Deserialization can be used. Please refer to the below link to know more about Serialization and Deserialization. 
 
 
Please make use of below code and sample, 

//Event Triggering 
this.FormClosing += Form1_FormClosing; 
//Event Customization 
private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
{ 
     //To serialize the GridConditionalFormatDescriptor to  XML file 
     XmlWriter writer = XmlWriter.Create("VisibleColumnsSchema.xml"); 
     this.gridGroupingControl1.WriteXmlSchema(writer); 
     writer.Close(); 
} 
this.Load += Form1_Load; 
 
//Event Customization 
private void Form1_Load(object sender, EventArgs e) 
{ 
     //DeSerialize the XML file to GridConditionalFormatDescriptorColloction 
     FileDialog dlg = new OpenFileDialog(); 
     dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; 
     if (dlg.ShowDialog() == DialogResult.OK) 
     { 
         XmlReader xr = new System.Xml.XmlTextReader(dlg.FileName); 
         //Apply the conditional formats. 
         this.gridGroupingControl1.ApplyXmlSchema(xr); 
         xr.Close(); 
     } 
} 
 
Suggestion 2 
In order to save the Visible columns collection before changing the datasource or refreshing the grid in FieldChooser, VisibleColumns.Changed event can be used.Please make use of below code and sample, 

//Event Triggering 
this.gridGroupingControl1.TableDescriptor.VisibleColumns.Changed += new Syncfusion.Collections.ListPropertyChangedEventHandler(VisibleColumns_Changed); 
 
private List<string> columns = new List<string>(); 
 
//Event Customization 
private void VisibleColumns_Changed(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e) 
{ 
               if (e.Action == Syncfusion.Collections.ListPropertyChangedType.Remove) 
               { 
                              string columnName = ((GridVisibleColumnDescriptor)e.Item).Name; 
                              if (! (columns.Contains(columnName))) 
                              { 
                                             columns.Add(columnName); 
                              } 
               } 
} 
 
//To refresh the grid 
private void refreshBtn_Click(object sender, EventArgs e) 
{ 
               this.gridGroupingControl1.DataSource = null; 
               this.gridGroupingControl1.DataSource = dataSource; 
               gridGroupingControl1.TableControl.Refresh(); 
               foreach (string name in columns) 
               { 
                              this.gridGroupingControl1.TableDescriptor.VisibleColumns.Remove(name); 
               } 
} 


Regards, 
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon