This is a migrated thread and some comments may be shown as answers.

SaveLayout of hierarchical grid

13 Answers 304 Views
GridView
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 28 Jan 2013, 03:14 PM
I have a grid with two levels of hierarchical grids and I use the SaveLayout / LoadLayout methods to save and restore the columns proporties of the grid, apparently the layout of the sub-grids is not stored in the XML file and there is no such properties on the sub-grids.
Is it possible to save and restore sub-grids layout ?

thanks in dvance

13 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 30 Jan 2013, 05:58 PM
Hi Pierre-Jean,

Thank you for writing.

You can change the default serialization metadata info to support this scenario. Here is a setup that allows the inner GridViewTemplates support save and load functionality:
public GridHierarchyCRUDForm()
{
    InitializeComponent();
 
    this.radGridView1.XmlSerializationInfo.DisregardOriginalSerializationVisibility = true;
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Clear();
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(RadGridView), "MasterGridViewTemplate", DesignerSerializationVisibilityAttribute.Content);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Templates", DesignerSerializationVisibilityAttribute.Content);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Caption", DesignerSerializationVisibilityAttribute.Visible);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Columns", DesignerSerializationVisibilityAttribute.Content);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "Name", DesignerSerializationVisibilityAttribute.Visible);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "Width", DesignerSerializationVisibilityAttribute.Visible);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "GroupDescriptors", DesignerSerializationVisibilityAttribute.Content);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GroupDescriptor), "GroupNames", DesignerSerializationVisibilityAttribute.Content);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(SortDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible);
    //Sort Descriptors           
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "SortDescriptors", DesignerSerializationVisibilityAttribute.Content);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(SortDescriptor), "Direction", DesignerSerializationVisibilityAttribute.Visible);
    //Filter Descriptors          
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "FilterDescriptors", DesignerSerializationVisibilityAttribute.Content);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Operator", DesignerSerializationVisibilityAttribute.Visible);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Value", DesignerSerializationVisibilityAttribute.Visible);
    this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "IsFilterEditor", DesignerSerializationVisibilityAttribute.Visible);
}


i hope this helps. Do not hesitate to contact us if you have further questions or issues.
All the best,
Julian Benkov
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 31 Jan 2013, 07:59 AM
Hello
I have added the following procedure which I invoke after the Initialize components in my form
but the XML file generated is "empty"
... may be that my "translation" to Visual Basic is not correct ?
thanks

   
Public Sub SaveLayoutWithTemplates(Grid As RadGridView)
        Grid.XmlSerializationInfo.DisregardOriginalSerializationVisibility = True
        Grid.XmlSerializationInfo.SerializationMetadata.Clear()
        Grid.XmlSerializationInfo.SerializationMetadata.Add("RadGridView", "MasterGridViewTemplate", DesignerSerializationVisibilityAttribute.Content)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("GridViewTemplate", "Templates", DesignerSerializationVisibilityAttribute.Content)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("GridViewTemplate", "Caption", DesignerSerializationVisibilityAttribute.Visible)

        Grid.XmlSerializationInfo.SerializationMetadata.Add("GridViewTemplate", "Columns", DesignerSerializationVisibilityAttribute.Content)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("GridViewDataColumn", "Name", DesignerSerializationVisibilityAttribute.Visible)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("GridViewDataColumn", "Width", DesignerSerializationVisibilityAttribute.Visible)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("GridViewTemplate", "GroupDescriptors", DesignerSerializationVisibilityAttribute.Content)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("GroupDescriptor", "GroupNames", DesignerSerializationVisibilityAttribute.Content)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("SortDescriptor", "PropertyName", DesignerSerializationVisibilityAttribute.Visible)
        'Sort Descriptors           
        Grid.XmlSerializationInfo.SerializationMetadata.Add("GridViewTemplate", "SortDescriptors", DesignerSerializationVisibilityAttribute.Content)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("SortDescriptor", "Direction", DesignerSerializationVisibilityAttribute.Visible)
        'Filter Descriptors          
        Grid.XmlSerializationInfo.SerializationMetadata.Add("GridViewTemplate", "FilterDescriptors", DesignerSerializationVisibilityAttribute.Content)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("FilterDescriptor", "PropertyName", DesignerSerializationVisibilityAttribute.Visible)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("FilterDescriptor", "Operator", DesignerSerializationVisibilityAttribute.Visible)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("FilterDescriptor", "Value", DesignerSerializationVisibilityAttribute.Visible)
        Grid.XmlSerializationInfo.SerializationMetadata.Add("FilterDescriptor", "IsFilterEditor", DesignerSerializationVisibilityAttribute.Visible)
    End Sub
0
Julian Benkov
Telerik team
answered on 04 Feb 2013, 05:22 PM
Hi Pierre-Jean,

The first parameter in the Add method of the SerializationMetadata is of type object and you should use the GetType operator of Visual Basic to feed with correct parameters. Here is a solution:

Imports Telerik.WinControls.UI
Imports Telerik.WinControls.Data
Imports System.ComponentModel
 
Public Class GridHierarchySerializationForm
 
    Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
        Me.RadGridView1.XmlSerializationInfo.DisregardOriginalSerializationVisibility = True
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Clear()
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(RadGridView), "MasterGridViewTemplate", DesignerSerializationVisibilityAttribute.Content)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "Templates", DesignerSerializationVisibilityAttribute.Content)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "Caption", DesignerSerializationVisibilityAttribute.Visible)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "Columns", DesignerSerializationVisibilityAttribute.Content)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewDataColumn), "Name", DesignerSerializationVisibilityAttribute.Visible)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewDataColumn), "Width", DesignerSerializationVisibilityAttribute.Visible)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "GroupDescriptors", DesignerSerializationVisibilityAttribute.Content)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GroupDescriptor), "GroupNames", DesignerSerializationVisibilityAttribute.Content)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(SortDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible)
        'Sort Descriptors           
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "SortDescriptors", DesignerSerializationVisibilityAttribute.Content)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(SortDescriptor), "Direction", DesignerSerializationVisibilityAttribute.Visible)
        'Filter Descriptors          
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "FilterDescriptors", DesignerSerializationVisibilityAttribute.Content)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(FilterDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(FilterDescriptor), "Operator", DesignerSerializationVisibilityAttribute.Visible)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(FilterDescriptor), "Value", DesignerSerializationVisibilityAttribute.Visible)
        Me.RadGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(FilterDescriptor), "IsFilterEditor", DesignerSerializationVisibilityAttribute.Visible)
    End Sub
End Class

I hope this helps.

Regards,
Julian Benkov
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 05 Feb 2013, 06:21 PM
Hello and thanks a lot for your contribution to answering my question.
It's better (a little), i.e. the XML file is created, however the MasterTemplate properties are not part of it and in the "sub-template" there is only the column name and not the other properties.
I realize that my inexperience is part of the problem ..
best regards
Pierre-Jean
0
Julian Benkov
Telerik team
answered on 07 Feb 2013, 10:24 PM
Hi Pierre-Jean,

The xml file contains information for the master template in its last section. To support binding operation, I extended this metadata information to serialize the FieldName and HeaderText information. Here is a set of the settings with the additional properties for serialization:

Me.radGridView1.XmlSerializationInfo.DisregardOriginalSerializationVisibility = True
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Clear()
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(RadGridView), "MasterTemplate", DesignerSerializationVisibilityAttribute.Content)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "Templates", DesignerSerializationVisibilityAttribute.Content)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "Caption", DesignerSerializationVisibilityAttribute.Visible)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "Columns", DesignerSerializationVisibilityAttribute.Content)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewDataColumn), "Name", DesignerSerializationVisibilityAttribute.Visible)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewDataColumn), "Width", DesignerSerializationVisibilityAttribute.Visible)
 
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewDataColumn), "FieldName", DesignerSerializationVisibilityAttribute.Visible)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewDataColumn), "HeaderText", DesignerSerializationVisibilityAttribute.Visible)
 
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "GroupDescriptors", DesignerSerializationVisibilityAttribute.Content)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GroupDescriptor), "GroupNames", DesignerSerializationVisibilityAttribute.Content)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(SortDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible)
'Sort Descriptors           
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "SortDescriptors", DesignerSerializationVisibilityAttribute.Content)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(SortDescriptor), "Direction", DesignerSerializationVisibilityAttribute.Visible)
'Filter Descriptors          
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(GridViewTemplate), "FilterDescriptors", DesignerSerializationVisibilityAttribute.Content)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(FilterDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(FilterDescriptor), "Operator", DesignerSerializationVisibilityAttribute.Visible)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(FilterDescriptor), "Value", DesignerSerializationVisibilityAttribute.Visible)
Me.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(GetType(FilterDescriptor), "IsFilterEditor", DesignerSerializationVisibilityAttribute.Visible)

Please view the attached video for additional details.

I hope this helps. If you have other questions, do not hesitate to contact me again.

All the best,
Julian Benkov
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Emilien
Top achievements
Rank 1
answered on 23 Oct 2013, 11:02 AM
Hi julian

I have the same problem as Pierre-jean but your solution does not work for me.
I created my hierarchical grid by adding a GridViewTemplate in my RadGridView with GridViewRelation.

Can you help me?


thanks
Emilien
0
George
Telerik team
answered on 28 Oct 2013, 09:59 AM
Hi Emilien,

Thank you for contacting us.

I successfully applied the solution my colleague - Julian proposed Pierre in a sample project. In the project I am also manually adding the relations just as you said you are doing in your project. Please, refer to the attached demo application for additional details.

Let me know if there is something else.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Louis
Top achievements
Rank 1
answered on 25 Jun 2014, 09:24 AM
Hi George

I have a similar problem in that my layout changes are not saved. I downloaded your demo project and it also has the same behaviour.

Here is what I do:
I open the project and hide one of the columns (I used Fax in your demo), clicked Save and then when I load the Fax column returns.
If I comment out the custom XmlSerializationInfo part from the Form Load, then the load will hide the Fax column correctly.

My own application does the exact same thing.

What am I doing wrong?
0
George
Telerik team
answered on 26 Jun 2014, 01:06 PM
Hi Louis,

Thank you for replying.

You should replace the code in the sample project with the following snippet, which has some slight modifications to serialize the IsVisible property:
this.radGridView1.XmlSerializationInfo.DisregardOriginalSerializationVisibility = false;
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Clear();
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(RadGridView), "MasterGridViewTemplate", DesignerSerializationVisibilityAttribute.Content);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Templates", DesignerSerializationVisibilityAttribute.Content);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Caption", DesignerSerializationVisibilityAttribute.Visible);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Columns", DesignerSerializationVisibilityAttribute.Content);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "Name", DesignerSerializationVisibilityAttribute.Visible);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "Width", DesignerSerializationVisibilityAttribute.Visible);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "DataSource", DesignerSerializationVisibilityAttribute.Hidden);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(new Telerik.WinControls.XmlSerialization.PropertySerializationMetadata(typeof(GridViewColumn).FullName, "IsVisible", true));
 
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "FieldName", DesignerSerializationVisibilityAttribute.Visible);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "HeaderText", DesignerSerializationVisibilityAttribute.Visible);
 
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "GroupDescriptors", DesignerSerializationVisibilityAttribute.Content);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GroupDescriptor), "GroupNames", DesignerSerializationVisibilityAttribute.Content);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(SortDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible);
//Sort Descriptors          
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "SortDescriptors", DesignerSerializationVisibilityAttribute.Content);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(SortDescriptor), "Direction", DesignerSerializationVisibilityAttribute.Visible);
//Filter Descriptors         
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "FilterDescriptors", DesignerSerializationVisibilityAttribute.Content);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Operator", DesignerSerializationVisibilityAttribute.Visible);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Value", DesignerSerializationVisibilityAttribute.Visible);
this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "IsFilterEditor", DesignerSerializationVisibilityAttribute.Visible);

I hope this information will be helpful.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Louis
Top achievements
Rank 1
answered on 26 Jun 2014, 02:41 PM
Hi George

Thank you. Your changes fixed it so that column visibility.

Is there a place where I can find a list of all the options available to save/load? 
I would like to also save the Sorting, Conditional Formatting, Grouping and Pinned states as well.

0
George
Telerik team
answered on 01 Jul 2014, 08:01 AM
Hello Louis,

Thank you for replying.

I tested the code I provided you with in my last reply and the sorting, filtering, grouping, pinned states of columns and conditional formatting objects were saved to the xml. 

Let me know if you require further assistance.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Louis
Top achievements
Rank 1
answered on 03 Jul 2014, 07:42 AM
Hi George

The only one that save\load correctly is the conditional formatting. 
Sorting, pinned states and grouping does not load. Also when I load the layout the child tables all become empty.

If you keep the app open and do the Save and then Load it looks like it is working, but when you restart the app and do a load you will see what I see.

Just to clarify this is what I do to test:
I open your demo app, set a conditional format on the Fax column, Pin the fax column to the left, group by the Region and Sort by Contact Name. Then I press Save and close the app.
When I start the app the default view is displayed. I then press load and expect to see my saved layout, but it does not.

I downloaded the latest Telerik updates yesterday and am running VS2012 Update4.

Below is my Form1_Load_1 after I updated it with your latest snippet:
private void Form1_Load_1(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'northwindDataSet.Products' table. You can move, or remove it, as needed.
            this.productsTableAdapter.Fill(this.northwindDataSet.Products);
            // TODO: This line of code loads data into the 'northwindDataSet.Suppliers' table. You can move, or remove it, as needed.
            this.suppliersTableAdapter.Fill(this.northwindDataSet.Suppliers);
 
            GridViewTemplate template = new GridViewTemplate();
            template.DataSource = this.northwindDataSet.Products;
            radGridView1.MasterTemplate.Templates.Add(template);
 
            GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
            relation.ChildTemplate = template;
            relation.RelationName = "SuppliersProducts";
            relation.ParentColumnNames.Add("SupplierID");
            relation.ChildColumnNames.Add("SupplierID");
            radGridView1.Relations.Add(relation);
 
            this.radGridView1.XmlSerializationInfo.DisregardOriginalSerializationVisibility = false;
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Clear();
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(RadGridView), "MasterGridViewTemplate", DesignerSerializationVisibilityAttribute.Content);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Templates", DesignerSerializationVisibilityAttribute.Content);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Caption", DesignerSerializationVisibilityAttribute.Visible);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Columns", DesignerSerializationVisibilityAttribute.Content);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "Name", DesignerSerializationVisibilityAttribute.Visible);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "Width", DesignerSerializationVisibilityAttribute.Visible);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "DataSource", DesignerSerializationVisibilityAttribute.Hidden);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(new Telerik.WinControls.XmlSerialization.PropertySerializationMetadata(typeof(GridViewColumn).FullName, "IsVisible", true));
 
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "FieldName", DesignerSerializationVisibilityAttribute.Visible);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "HeaderText", DesignerSerializationVisibilityAttribute.Visible);
 
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "GroupDescriptors", DesignerSerializationVisibilityAttribute.Content);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GroupDescriptor), "GroupNames", DesignerSerializationVisibilityAttribute.Content);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(SortDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible);
            //Sort Descriptors         
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "SortDescriptors", DesignerSerializationVisibilityAttribute.Content);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(SortDescriptor), "Direction", DesignerSerializationVisibilityAttribute.Visible);
            //Filter Descriptors        
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "FilterDescriptors", DesignerSerializationVisibilityAttribute.Content);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Operator", DesignerSerializationVisibilityAttribute.Visible);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Value", DesignerSerializationVisibilityAttribute.Visible);
            this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "IsFilterEditor", DesignerSerializationVisibilityAttribute.Visible);
        }


Thank you.
0
George
Telerik team
answered on 07 Jul 2014, 03:06 PM
Hello Louis,

Thank you for writing.

Since some object types are not meant to be serializable, you should handle this manually. I recommend you to read about Custom Serialization since this is what you will probably use. I can give you a quick example of how to serialize a ConditionalFormattingObject and all of its public properties and then deserialize it to an object once again. You will need to create a derived class from ConditionalFormattingObject, mark it as Serializable by setting an attribute and implement the ISerializable interface. This interface obligates you to tell the serializer all the properties you want to serialize as well as its values: 
[Serializable()]
public class MyConditionalFormattingObject : ConditionalFormattingObject, ISerializable
{
    public MyConditionalFormattingObject() : base("NewCondition", ConditionTypes.Equal, string.Empty, string.Empty, false)
    {
    }
  
    public MyConditionalFormattingObject(string name, ConditionTypes type, string tvalue1, string tvalue2, bool applyToRow) : base(name, type, tvalue1, tvalue2, applyToRow)
    {
    }
  
    #region "ISerializable Members"
  
    public MyConditionalFormattingObject(SerializationInfo info, StreamingContext context)
    {
        PropertyInfo[] properties = typeof(ConditionalFormattingObject).GetProperties();
        foreach (PropertyInfo prop in properties) {
            prop.SetValue(this, info.GetValue(prop.Name, prop.PropertyType));
        }
    }
  
  
    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        PropertyInfo[] properties = typeof(ConditionalFormattingObject).GetProperties();
        foreach (PropertyInfo prop in properties) {
            info.AddValue(prop.Name, prop.GetValue(this));
        }
    }
  
    #endregion
}

Now we can create an instance of our custom class and and serialize it to a file: 
MyConditionalFormattingObject obj = new MyConditionalFormattingObject("MyCondition", ConditionTypes.Greater, "30", "", false);
obj.CellBackColor = Color.SkyBlue;
obj.CellForeColor = Color.Red;
obj.TextAlignment = ContentAlignment.MiddleRight;
  
IFormatter formatter = new BinaryFormatter();
using (Stream stream = new FileStream("MyFile.bin", FileMode.OpenOrCreate))
{
    formatter.Serialize(stream, obj);
}

You can as easily deserialize it:
MyConditionalFormattingObject obj2 = null;
using (Stream stream = new FileStream("MyFile.bin", FileMode.OpenOrCreate))
{
    obj2 = (MyConditionalFormattingObject)formatter.Deserialize(stream);
}

Feel free to implement any further functionality.

I hope this helps.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Julian Benkov
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Emilien
Top achievements
Rank 1
George
Telerik team
Louis
Top achievements
Rank 1
Share this question
or