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

Save and loadlayout xml manipluation

3 Answers 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
nitin b
Top achievements
Rank 1
nitin b asked on 23 Aug 2010, 11:21 PM
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.









3 Answers, 1 is accepted

Sort by
0
erwin
Top achievements
Rank 1
Veteran
answered on 24 Aug 2010, 10:53 AM
Nitin,

Have a look at the XmlSerialization Property:

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

Regards
Erwin
0
Cristian Apavaloaiei
Top achievements
Rank 2
answered on 09 Feb 2011, 11:54 AM
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
0
Julian Benkov
Telerik team
answered on 14 Feb 2011, 05:47 PM
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.
Tags
GridView
Asked by
nitin b
Top achievements
Rank 1
Answers by
erwin
Top achievements
Rank 1
Veteran
Cristian Apavaloaiei
Top achievements
Rank 2
Julian Benkov
Telerik team
Share this question
or