Home Forums WinForms controls Xceed Grid for WinForms save grid contents to xml

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13646 |

    How can I save unbound grid contents to a xml file?

    Imported from legacy forums. Posted by PETE (had 2473 views)

    User (Old forums)
    Member
    Post count: 23064

    <code>XmlTextWriter writer = new XmlTextWriter(“grid.xml”, Encoding.UTF8);
    writer.WriteStartDocument();
    writer.WriteStartElement(“grid”);
    foreach(Xceed.Grid.DataRow row in grid.DataRows)
    {
    writer.WriteStartElement(“row”);
    foreach(Xceed.Grid.Cell cell in row.Cells)
    {
    string strValue;
    if (cell.Value == null || cell.Value is DBNull) strValue = “”;
    else strValue = cell.Value.ToString();
    writer.WriteAttributeString(cell.ParentColumn.FieldName, strValue);
    }
    writer.WriteEndElement();
    }
    writer.WriteEndElement();
    writer.Close();</code>
    This will produce an XML-file that looks like this:<code><?xml version=”1.0″?>
    <grid>
    <row field1=”value1″ field2=”value2″ field3=”value3″ />
    <row field1=”value1″ field2=”value2″ field3=”value3″ />
    <row field1=”value1″ field2=”value2″ field3=”value3″ />
    </grid></code>

    Imported from legacy forums. Posted by Tommy (had 219 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you Tommy

    Imported from legacy forums. Posted by PETE (had 3454 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.