Ticket Q481265
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

How to Save and Open Layout to XML?

How to Save Winform to XML file and Open to Load it with Browse button?

created 12 years ago

Hi.
I try to create Winform application with Grid and Chart and Bar.
I want to save it to XML file with browse button, and also I can open and reload it any time with browse button?
how to act this?
can I get any sample for this issue?

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hello,
The GridView, BarManager (etc.) components can save its layouts via the SaveLayoutToXml method.
However, as far as I understand you wish to save layout of several controls to one XML file. Please refer to the How to Save and Open Layout to XML? topic where this task was considered.
If this solution does not meet your requirements, describe your final goal in greater detail.
I hope you find this information useful and am looking forward to your results once you try this solution.

    Show previous comments (1)
    DevExpress Support Team 12 years ago

      If you wish to specify file names, I suggest you use standard WinForms components:
      SaveFileDialog
      FileDialog
      OpenFileDialog

        I got confuse with some issue when i try to load with load button.
        in the sample, column was created by DataTable, but my program created column by TreeListColumn.
        this is my code:
        private void CreateColumn(TreeList tl)
        {
                    tl.BeginUpdate();
                    tl.Name = "Table1";
                    string[] caption = { "caption1", "caption2", "caption3", "caption4", "caption5", "caption6", "caption7", "caption8", "caption9",
                                       "caption10", "caption11", "caption12", "caption13"};
                    for (int i = 0; i < 13; i++)
                    {
                        tl.Columns.Add();
                        tl.Columns[i].Caption = caption[i];
                        tl.Columns[i].VisibleIndex = i;
                        tl.Columns[i].FieldName = caption[i];
                        tl.Columns[i].Name = caption[i];
                        tl.Columns[i].BestFit();
                        tl.ExpandAll();
                    }
                  tl.EndUpdate();
        }
        and the sample code:
        private static DataTable CreateTable(int RowCount) {
                    DataTable tbl = new DataTable();
                    tbl.TableName = "Table1";
                    tbl.Columns.Add("Name", typeof(string));
                    tbl.Columns.Add("ID", typeof(int));
                    tbl.Columns.Add("ParentID", typeof(int));
                    tbl.Columns.Add("Number", typeof(int));
                    tbl.Columns.Add("Date", typeof(DateTime));
                    for (int i = 0; i < RowCount; i++) {
                        tbl.Rows.Add(new object[] { String.Format("Name{0}", i), i + 1, -1, 3 - i, i,DateTime.Now.AddDays(i) });
                    }
                    return tbl;
        }
        the issue is:
        private void simpleButton2_Click(object sender, EventArgs e) {
                    XElement LayoutElement = XElement.Load("Result.xml");
                    string LayoutFileName = "Result.xml";
                    FileStream LayoutFile = new System.IO.FileStream(LayoutFileName, System.IO.FileMode.Open);
                    treeList1.RestoreLayoutFromStream(LayoutFile, OptionsLayoutBase.FullLayout);
                    LayoutFile.Close();
                    MemoryStream DataFile = new System.IO.MemoryStream();
                    LayoutElement.Element("DataSet").Elements().First().Save(DataFile);
                    DataFile.Seek(0, SeekOrigin.Begin);
                    ds.Clear();
                    ds.ReadXml(DataFile);
                    treeList1.DataSource = ds.Tables["Table1"]; //this is the issue, cause I made column with TreeListColumn, no DataTable
                    int foo = ds.Tables["Table1"].Rows.Count; //this is the issue
        }
        thank you.

        DevExpress Support Team 12 years ago

          The sample project in the How to Save and Open Layout to XML? topic illustrates how to add xml data as a separate node to other xml data. If you do not need to save TreeList data, you can exclude the code where the DataSet is saved. TreeList saves columns in its layout data, thus, there is no need to save and load them separately.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.