Create a text line out of a Custom Class Tree
<p>I have created a custom class, which is filled with data, called AssociatedMetaChain.</p>

<p>These are the variables within this class which you will require to solve, there are many more containing more data foreach of these parent and children, like a description.</p>

<pre><code>int parentID;
int childID;
List&lt;AssociatedMetaChain&gt; Links;
</code></pre>

<p>The Links variable contains a list all the children of childID.
Thus in Links childID becomes parentID over and over and over again.</p>

<p>And so we create a tree of data lineage illustrated below.</p>

<p>AB<br>
.BC<br>
..CF<br>
...FP<br>
.BD<br>
..DE<br>
...EZ<br>
..DR<br>
...RY 
..DS<br>
...SQ</p>

<p>Now i need to turn that into specific lines like this</p>

<p>Line 1 : ABCFP<br>
Line 2 : ABDEZ<br>
Line 3 : ABDRY<br>
Line 4 : ABDSQ</p>

<p>I have written recursive code in an attempt to achieve this result and can successfully create Lines one and two.
The other 2 return what is displayed as below</p>

<p>Line 3 : ABRY
Line 4 : ABSQ  </p>

<p>Skipping D</p>

<p>In a button click I have this code which runs through the parent list of Chains<br>
There is also a child list of chains because I need to reverse the lines as well, it follows suite.
Once this has completed myLines saves into a CSV file. oh joy</p>

<pre><code>    private string myLines;
    {
            foreach (AssociatedMetaChain parent in parents)
                    {
                            addChildren(parent, parent); //THIS LINE CREATES THE TREE ABOVE
                            myLines += createLines(parent, parent, true);
                    }
    }

//This calls createLines below which returns string r into itself until there are no more children in the Links variable of the rootparent passed in above

                private string createLines(
                                          AssociatedMetaChain rootParent,
                                          AssociatedMetaChain parent,
                                          bool isStart
                                          )
            {
                string r = "";
                if (isStart)
                {

    r += parent.ParentID + ",";
    r += parent.ChildID + ",";

                }
                if (parent.Links.Count == 0 &amp;&amp; isStart)
                {
                    r += "\n";
                }
                else
                {
                    foreach (AssociatedMetaChain link in parent.Links)
                    {

                        if (link.Links.Count == 0)
                        {
                            r += link.childPKID + ",";
                            r += "\n";

//This is where I try and repeat the missing information but cant seem to figure out a   way how far down the loop is inside of its own tree to know what index to use in Links,   hence the rootParent Variable which helps for the first not the rest

                            r += rootParent.parentID + ",";
                            r += rootParent.childID + ",";
                        }
                        else
                        {                       
                            r += link.childPKID + ",";
                        }

                        r += createLines(rootParent, link, false);
                    }
                }
                return r;
            }
        }
</code></pre>

<p>If the great minds of the interwebs are able to help in any way, I will send you a real live cat.  If not, I will find a solution eventually and post the result here.
Thanks for any criticism you could tarnish my mind with, I love it!</p>

<p>Good Day ;)</p>
