これは簡単ではありません。私は常に Winforms ツリービューをコーディングしています。コードのチャンクがいくつかあり、それらはすべて大きいです。
ParentItem というクラスを作成します。ParentItem 内には、Children という名前の ParentItem のコレクションがあります。要するに、各要素はそれ自体のさらなるインスタンスのリストを含むことができなければなりません。
したがって、ある時点で次のようなコードが表示
されることがあり
ParentNode x1 = new ParentNode(1, "Item1"); // constructor contains record Id field and descriptive text
x1.Children.Add(new ParentNode(1, "ChildItem1"); // under the presumption the record Id is for a different table
x1.Children[0].Children[0].Add(new ParentNode(7, "ChildItem7"); // third level, not 5th level as in your example
ます。ノードをツリービュー コントロールに追加すると、子が子の子に追加されます。
これは簡単なアイデアであり、実際の実装はもっと複雑です。