Hello There
im trying to populte treeView control with xml file
The tree is beeing populted but with the nodes tages name
like in this Case the child Tag
i just want to show under General:
General
-var3
-var 4
and NOT x NOT(as it happen)
General
-child
---var 3
-child
---var 4
The XML file:
pattu tPosted Jan 31, 2011, 12:48 AM
-var3
-var 4
and NOT x NOT(as it happen)
General
-child
---var 3
-child
---var 4
The XML file:
I am also getting the same problem colud you pls send me the code to correct this issue to [email protected]
kobi shaalPosted Jul 27, 2007, 4:45 AM
i mange withe the code you sent me,one more thing how can i add a diffrenet image for
the root node and to the the child node?
i get the same image to all of the nodes
Thanks ahead!
kobi shaalPosted Jul 27, 2007, 3:04 AM
private void buttonSetTree_Click(object sender, System.EventArgs e)
{
try
Create a DOM Document and load the XML data into it.
XmlDocument dom =
new XmlDocument();dom.Load(textBox1.Text);
Initialize the TreeView control.treeView1.Nodes.Clear();
treeView1.Nodes.Add(
new TreeNode(dom.DocumentElement.Name));TreeNode tNode =
new TreeNode();tNode = treeView1.Nodes[0];
treeView1.ImageList=imageList1;
// SECTION 3. Populate the TreeView with the DOM nodes.AddNode(dom.DocumentElement, tNode);
treeView1.ExpandAll();
}
catch(XmlException xmlEx){
MessageBox.Show(xmlEx.Message);
}
catch(Exception ex){
MessageBox.Show(ex.Message);
}
}
private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode){
XmlNode xNode;
TreeNode tNode=
null;XmlNodeList nodeList;
int i; // Loop through the XML nodes until the leaf is reached. // Add the nodes to the TreeView during the looping process. if (inXmlNode.HasChildNodes){
nodeList = inXmlNode.ChildNodes;
for(i = 0; i<=nodeList.Count - 1; i++){
xNode = inXmlNode.ChildNodes[i];
inTreeNode.Nodes.Add(
new TreeNode(xNode.Name));inTreeNode.ImageIndex = 1;
tNode = inTreeNode.Nodes[i];
AddNode(xNode, tNode);
}
}
else{
inTreeNode.Text = (inXmlNode.OuterXml).Trim();
}
}
}
}
Jan MontanoPosted Jul 26, 2007, 10:32 PM
How are you populating your treeview? Could you post your sample code?
XmlDocument xml = new XmlDocument();
xml.Load(@"G:\temp\kobi.xml");
// xml.FirstChild = ?xml version="1.0"?
XmlNode rootNode = xml.FirstChild.NextSibling; // Vars
foreach (XmlNode mainXmlNode in rootNode.ChildNodes)
{
}