)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to load and save TreeNodeAdv in WinForms TreeViewAdv using XML file?

Platform: WinForms |
Control: TreeViewAdv |
Published Date: December 10, 2014 |
Last Revised Date: February 5, 2020

Load and save the TreeNodeAdv using XML file

You can load and save the TreeNodeAdv in TreeViewAdv using XML file as given in the following code example.

C#

// To load the TreeNodeAdv from XML file
private void addTreeNode(XmlNode xmlNode, TreeNodeAdv treeNode)
{
   XmlNode xNode;
   TreeNodeAdv tNode;
   XmlNodeList xNodeList;
   if(xmlNode.HasChildNodes)
   {
      xNodeList = xmlNode.ChildNodes;
      for(int x = 0; x <= xNodeList.Count - 1; x++)
      {
          xNode = xmlNode.ChildNodes[x];
          treeNode.Nodes.Add(new TreeNodeAdv(xNode.Name));
          tNode = treeNode.Nodes[x];
          addTreeNode(xNode, tNode);
      }
   }
   else 
      treeNode.Text = xmlNode.OuterXml.Trim();
}
// To save the TreeNodeAdv to XML file
private void saveNode2(TreeNodeAdvCollection tnc)
{
   foreach (TreeNodeAdv node in tnc)
   {
       if(node.Nodes.Count > 0)
       {
          xr.WriteStartElement(node.Text);
          saveNode2(node.Nodes);
          xr.WriteEndElement();
       }
       else
       {
          xr.WriteString(node.Text);
       }
   }
}

VB

‘ To load the TreeNodeAdv from XML file
Private Sub addTreeNode(xmlNode As XmlNode, treeNode As TreeNodeAdv)
   Dim xNode As XmlNode
   Dim tNode As TreeNodeAdv
   Dim xNodeList As XmlNodeList
   If xmlNode.HasChildNodes Then
      xNodeList = xmlNode.ChildNodes
      For x As Integer = 0 To xNodeList.Count - 1
          xNode = xmlNode.ChildNodes(x)
          treeNode.Nodes.Add(New TreeNodeAdv(xNode.Name))
          tNode = treeNode.Nodes(x)
          addTreeNode(xNode, tNode)
      Next
   Else
      treeNode.Text = xmlNode.OuterXml.Trim()
   End If
End Sub
‘ To save the TreeNodeAdv to XML file
Private Sub saveNode2(tnc As TreeNodeAdvCollection)
   For Each node As TreeNodeAdv In tnc
       If node.Nodes.Count > 0 Then
          xr.WriteStartElement(node.Text)
          saveNode2(node.Nodes)
          xr.WriteEndElement()
       Else
          xr.WriteString(node.Text)
       End If
   Next
End Sub

Sample: http://www.syncfusion.com/downloads/support/directtrac/general/LoadTreeNodeAdvfromXML1530078861.zip

Reference link: https://help.syncfusion.com/windowsforms/treeview/save-and-load-xml

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon