Hello Everyone,
I need your help. As with the Subject written. I want to insert data into a UltraWinGrid (at the beginning was empty) at runtime.
Then save these data from the UltraWinGrid to a XML-File. How can I do this? Should I produce a DataTable in Database or could I directly save these data to XML without database?
Hi Leo,
The grid has no exporting to XML functionality. So you could use a DataTable/DataSet. Or you could write code to write the XML yourself.
I might be able to offer you a better solution if I knew why you wanted to export the data to XML and what you want to do with it.
Hi Mike,
thanks for your information. I've already done.
Leo
Hi,
Here is the code to do that:
You need first to assign the datasource table a namespace.
mytable.Namespace = "Table1"
Me.UltraGrid1.DataSource = mytable
Then call the function UltraGridToXmlDocument by the grid name and assign a value for the Item.
xml = UltraGridToXmlDocument(UltraGrid1, "Item")
Private Function UltraGridToXmlDocument(ByRef UG As UltraGrid, ByVal Item As String) As XmlDocument
Dim xml As New XmlDocument()
Dim sb As New StringBuilder()
sb.Append("<?xml version='1.0' encoding='utf-8' ?>")
sb.Append("<" + UG.DataSource.NameSpace.ToString() & ">")
For Each dr As UltraGridRow In UG.Rows
sb.Append("<" + Item & ">")
For Each dc As UltraGridColumn In UG.DisplayLayout.Bands(0).Columns
If dc.Hidden = False Then
sb.Append(("<" + dc.Header.Caption & ">" & dr.Cells(dc.Index).Value & "</") + dc.Header.Caption & ">")
End If
Next
sb.Append("</" + Item & ">")
sb.Append("</" + UG.DataSource.NameSpace.ToString() & ">")
xml.LoadXml(sb.ToString())
Return xml
}
The output xml you can save to a file.
xml.Save("C:\Report\WinGrid_xml.xml")