c# - how to find child nodes at root node [TreeView] -
root b c d e t f g x
i want find e node's parent nodes(it number 5). then, i'll save node. if number smaller 5. i'm using treeview in asp.net control.
i suggest using recursive iterations.
private treenode findnode(treeview tvselection, string matchtext) { foreach (treenode node in tvselection.nodes) { if (node.tag.tostring() == matchtext) { return node; } else { treenode nodechild = findchildnode (node, matchtext); if (nodechild != null) return nodechild; } } return (treenode)null; }
you can utilize logic determine many things node , structure allows expand can node , criteria wish search for. can edit example fit own needs.
thus, example pass in e , expect have node e returned if parent property of node returned parent after.
tn treenode = findnode(mytreeview, "e")
tn.parent
value after.
Comments
Post a Comment