Getting single treeview node by path

  • Thread starter =?iso-8859-1?q?Christian_R=FChl?=
  • Start date
?

=?iso-8859-1?q?Christian_R=FChl?=

heyho, guys! here's another question for you now:

i built an iterator to get all the nodes with a certain attribute in an

xml dom. it all looks like this (i'm using .NET framework 1.1)


string xpath;


// iterate over all xmlnodes with attribute "status='checked'"
XPathDocument xpathDoc = new XPathDocument(m_configFile);
XPathNavigator xpathNav = xpathDoc.CreateNavigator();
XPathNodeIterator nodeIter = xpathNav.Select(@"/*[@status='checked']");



while(nodeIter.MoveNext())
{
xpath = nodeIter.CurrentPosition.ToString();
// here i want to address an treeview node with the xpath to
set its
checkbox

}


so what i want to know is: how can i address a treeview node by it's
path? for if i go like
treeView1.SelectedNode.blabla it randomly choses a node in treeView
control.
 
?

=?iso-8859-1?q?Christian_R=FChl?=

Solution found:

string xpath = null;
XmlNode configNode = configDom.DocumentElement;
// collect selected nodes in node list
XmlNodeList nodeList =
configNode.SelectNodes(@"//*[@status='checked']");

//MessageBox.Show(Convert.ToString(nodeList.Count));

// loop through nodelist
foreach(XmlNode myNode in nodeList)
{
xpath = GetPathFromNode(myNode); // get node path
xpath = xpath + "\\" + myNode.InnerText.ToString(); // complete path
string
}
 
?

=?iso-8859-1?q?Christian_R=FChl?=

oh, and of course the following:

//Loop through the Parent Nodes
for(int k=0; k<treeView1.Nodes.Count; k++)
{
root = treeView1.Nodes[k]; // parent node

if(("\\"+root.FullPath.ToString()) == xpath) // compare paths
root.Checked=true; // set checkbox if node is found in tree view

// loop childs of root
for (int i=0; i<root.Nodes.Count; i++)
VisitChildNodes(root.Nodes, xpath);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top