// Manage Tree View Nodes in RunTime
// In order to manage a node you should set a key for each node
// in your case records id's could be fine
treeView1.Nodes.Add("RootNode1Key","Root Node1");
treeView1.Nodes.Add("RootNode2Key", "Root Node2");
// adds a node in runtime with title Root Node
//Now add a Child to "Root Node 2"
// first find the node and make a pointer to it :^)
TreeNode FoundedNode;
FoundedNode = treeView1.Nodes.Find("RootNode2Key", true)[0];
// if you create a unique key for each node the find function returns
// a tree node array with only one node and you access it like above
// else you retrieve many records of TreeNode
FoundedNode.Nodes.Add("RootNode2Childe1", "Root Node2 Child 1");
// hey now you added a child node to RootNode2
// you want to add a child for it in depth
// 2 ways :
// 1: yous find method treeView1.Nodes.Find("RootNode2Childe1", true)[0];
// 2: Following
FoundedNode.Nodes["RootNode2Childe1"].Nodes.Add("RootNode2Childe1Child1", "my parent is RootNode2Childe1");
これで、1つを削除したい場合は、次のように簡単です。
private void button2_Click(object sender, EventArgs e)
{
// i am sure you know how to add nodes now remove a node
TreeNode FoundedNode;
FoundedNode = treeView1.Nodes.Find("RootNode2Childe1Child1", true)[0];
FoundedNode.Remove();
}
しかし、ネットを検索することをお勧めします。データソースを使用して、テーブルにレコードを追加し、レコードを削除すると、ツリービューが更新され、その逆も可能です。
*このコミュニティのメンバーシップを他のイラン人やプログラマーに提供します*