Proper way to set parent of a tree node in C#?
<p>I'm working on a custom tree. Each node (BindingNode is how I call them) contains a BindingNodeCollection that implements <a href="http://msdn.microsoft.com/en-us/library/92t2ye13.aspx" rel="nofollow">ICollection</a> and contains more nodes. My problem is that, the user should be able to access each node's parent with a readonly property called Parent, just like in a <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.aspx" rel="nofollow">TreeNode</a>. But the nodes are added to a BindingNodeCollection by calling BindingNodeCollection's <code>Add(BindingNode node)</code> method. BindingNodeCollection knows what it's own parent is, but, can't assign BindingNode's Parent in the  <code>Add(BindingNode node)</code> method because Parent should be readonly. The functionality I'm trying to achieve is basically the same as the functionality of a <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.aspx" rel="nofollow">TreeNode</a> and a <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.treenodecollection.aspx" rel="nofollow">TreeNodeCollection</a> in a <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx" rel="nofollow">TreeView</a>: </p>

<p>-TreeNode's Parent is readonly.</p>

<p>-TreeNodes are assigned to a TreeNodeCollection by calling TreeNodeCollection's <code>Add(TreeNode node)</code> method.</p>

<p>-TreeNode's Parent gives the TreeNode that contains the TreeNodeCollection where the TreeNode was added.</p>

<p>-TreeNodeCollection is NOT defined inside TreeNode in order to have access to the Parent private field.</p>

<p>This is when I miss C++'s <code>friend</code>. :(</p>
