Save and loadlayout xml manipluation

4 posts, 0 answers
  1. nitin b
    nitin b avatar
    7 posts
    Member since:
    Jan 2010

    Posted 23 Aug 2010 Link to this post

    Hi

    I want to use xml from savelayout and loadlayout.

    but i want some specific properties from xml. i.e. i want to save some specific properties of xmlnode.

    for eg.

     StringBuilder stbTmp = new StringBuilder();
                using (XmlWriter writer = XmlWriter.Create(stbTmp))
                {
                    rgvCustom.SaveLayout(writer);
                }

    Generated Output:
    <Telerik.WinControls.UI.GridViewDecimalColumn FormatString="" Width="92" FieldName="h_company_id" Name="h_company_id" IsAutoGenerated="True" IsVisible="True" HeaderText="h_company_id" TextAlignment="MiddleRight" />

    I want to following string.
    Expected Output
    <Telerik.WinControls.UI.GridViewDecimalColumn FormatString="" FieldName="company_id" Name="company_id"  HeaderText="company id" TextAlignment="MiddleRight" />

    how can get above string in savelayout except........ IsAutoGenerated="True" IsVisible="True"

    Please let me know.

    thanks.









  2. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 24 Aug 2010 Link to this post

    Nitin,

    Have a look at the XmlSerialization Property:

    http://www.telerik.com/support/kb/winforms/gridview/utilizing-radgridview-s-serialization-api.aspx

    Regards
    Erwin
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Cristian Apavaloaiei
    Cristian Apavaloaiei avatar
    25 posts
    Member since:
    Aug 2008

    Posted 09 Feb 2011 Link to this post

    Hi, 
    I am using the last release (Q3.1215) of Telerik.WinControls and i have this situation:
    Having an IList datasource for my radgridview, i generate columns from the type of the data for each column. For fields that are double, int or decimal i generate a GridViewDecimalColumn and set the corresponding DataType property. When saving layout i want to serialize the DataType property for GridViewDecimalColumns. I have tried:   
    "
     this.radGridView1.XmlSerializationInfo.SerializationMetadata.Add(
     typeof(GridViewDecimalColumn), "DataType",
    DesignerSerializationVisibilityAttribute.Visible);
    " but it does not work .
    Here is a sample code :

    grid.Columns.Clear();
                    foreach (string prop in ColumsDataSouce.Keys) //  ColoaneDataSouce is a Dictionary<string, Type>
                    {     // that contains each field from my dataSource with //type&Name
                        if (ColoaneDataSouce[prop] != typeof(Guid))
                        {
                            GridViewDataColumn coloana = null;
                            Type tipData = ColoaneDataSouce[prop];
                            string text = prop.ToUpper();
                            if ((tipData == typeof(bool)) || (tipData == typeof(bool?)))
                            {
                                coloana = new GridViewCheckBoxColumn();
                            }
                            else if (((tipData == typeof(int)) || (tipData == typeof(int?)) ||
                                     (tipData == typeof(decimal)) || (tipData == typeof(decimal?)) ||
                                     (tipData == typeof(double)) || (tipData == typeof(double?))))
                            {
                                
                                coloana = new GridViewDecimalColumn();
                                (coloana as GridViewDecimalColumn).ShowUpDownButtons = false;
                                (coloana as GridViewDecimalColumn).DataType = tipData;
                                string format = "{0:N0}";


                                if (tipData == typeof(int) || tipData == typeof(int?))
                                {
                                    (coloana as GridViewDecimalColumn).DecimalPlaces = 0;
                                    (coloana as GridViewDecimalColumn).ThousandsSeparator = false;
                                }
                                else
                                {
                                    (coloana as GridViewDecimalColumn).DecimalPlaces = 2;
                                    (coloana as GridViewDecimalColumn).ThousandsSeparator = true;
                                }
     }
                            else
                            {
                                coloana = new GridViewTextBoxColumn();
                                if ((tipData == typeof(DateTime)) || (tipData == typeof(DateTime?)))
                                {
                                    coloana.FormatString = "{0:d}";
                                }
                            }


                            string numeTextRaport = prop;
                            coloana.WrapText = true;
                            coloana.HeaderTextAlignment = ContentAlignment.MiddleCenter;
                            coloana.HeaderText = numeTextRaport ;
                            coloana.IsVisible = true;
                            coloana.Name = prop;
                            coloana.FieldName = prop;
                            coloana.VisibleInColumnChooser = true;
                            grid.MasterTemplate.Columns.Add(coloana);


                        }
                    }

    In hope of a positive response, I wish you a great day
  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 14 Feb 2011 Link to this post

    Hi Cristian Apavaloaiei,

    You can not serialize the Type property using our XML serialization component. This is because the Type property can reference an unknown object and we cannot serialize/deserialize its value. I recommend using the LayoutLoaded event instead. When handling this event you can explicitly specify the DataType property using the Name of the column. 

    I hope this helps. If you have further questions, I will be glad to be of assistance.

     Kind regards,
    Julian Benkov
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Back to Top