algorithm - C# TreeView append all possible sequential nodes as string -


I have difficulties applying text to the tree squares nodes as shown in the picture.

I am trying to get all the possible methods of parenting node and attached child nodes in the following:

  • a -> B -> c -> d
  • a -> b -> c -> e
  • a -> b -> f

me It's written in the C # code but it's not working properly. I want it and I'm stuck on this problem, so I'm asking for your help.

  Private static list & lt; Node & gt; GetChildNodes (node ​​node, list & lt; node & gt; parent nodes) {list & lt; Node & gt; Nodes nodes = new list & lt; Node & gt; (); NodesNodes.Add (node); If (node.childnodes.nei)) {foreach (ChildNode in node. ChildNode) {nodes nodes.adrenence (Gatechildnodes (ChildNode, Parentnode)); }} Return nodes; } List & lt; Node & gt; Attached nodes = new list & lt; Node & gt; (); Foreach (Var node in parent nodes) // All of my parents node db (that is, with parentID = null) {var nodes = gatechildrenodes (node, parent node); Select string fulnode = string .joined (",", nodes. Order by desending (n => n. parent id). (N = & gt; n.Name)); Aid nodes.ad (node ​​node () {id = nodes. Ordering providence (l = & gt; l.pent id). First () .id, name = fulnode, punter id = node, paint id); }  

Then I name (which is in the form of A - B) - Attached nodes > in the UI by showing the property C ....)

But this gives me the result according to the picture: a -> b -> c -> d -> e -> f

Give a head with the solution? thank you in advanced!

If you only want string representation of all the paths in your tree, then you can do very well Use TreeNode.FullPath if you want the path as a node archive, then you can use TreeNode.Tag and the strings in the archive stored in the tags of the node Instead of adding to Running app

  Public IEnumerable & lt; String & gt; GetTagPaths (TreeView TV) {GetTagPaths (tv.Nodes [0]); } Public IEnumerable & lt; String & gt; GetFullPaths (TreeView TV) {GetFullPaths back (tv.Nodes [0]); } Public IEnumerable & lt; String & gt; GetTagPaths (tree node node) {if (node.Tag == faucet} string. ISOILORAPT (Tot as node string)) node. Tag = node Text; Foreach (tree node in node. Nodes) {child.Tag = (node ​​tag as string) + "- & gt;" + Child Text; If (child.IsLeaf ()) returns yield (as child.Tag string); Other foreign currency (string childpath in GetTagPaths (child)) returns child path; }} Public IEnumerable & lt; String & gt; GetFullPaths (tree node node) {if (node. ISLF) yield returns node. Flowerpath; Other foreign currency (tree node in node. Node) {Advance (string childpath in gatefulpath (hair)); Return baby cap; }}  

and this extension method

  public Static Bull ISLF (this system.wondo.forms.tnn) {System.Windows.Forms.TreeNodeCollection children = TN Nodes; Return (children == weaken; child; number == 0); }  

Comments