I have to load an Xml document and display in a tree view in a winform. here is a piece of code. Please tell whats the error.
private void AddingNodesToTree(ref XmlNode xnode, ref TreeNode tnode)
{
TreeNode subNode = treeNodes.Add(xnode.Name);
subNode.Tag = xnode;
foreach (XmlNode subElement in xnode.ChildNodes)
{
AddingNodesToTree(subNode.Nodes, subElement);
}
}
after this i select node in that tree to display the attributes of selected node:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
XmlNode xNode = e.Node.Tag as XmlNode;
if (xNode != null)
{
foreach (XmlNode subNode in xNode.ChildNodes)
{
listBox1.Items.Add(subNode.Name);
}
}
}
WHats possible error in this code? Please rectify.