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.
Unfortunately, activation email could not send to your email. Please try again.

FieldChooser and saving new layout of selected columns

Thread ID:

Created:

Updated:

Platform:

Replies:

131026 Jun 16,2017 02:15 PM Jun 19,2017 05:30 AM Windows Forms 1
loading
Tags: GridGroupingControl
Josip Pejakovic
Asked On June 16, 2017 02:15 PM

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.

Arulpriya Ramalingam [Syncfusion]
Replied On June 19, 2017 05:30 AM

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;