TreeView控件顯示結點層次結構
CkeckBox屬性設定為True則可以選擇;
TreeView的集合Nodes是TreeNode對象
TreeNode tn = new TreeNode();
//添加結點:
if (textBox1.Text.Trim() == "") return;
TreeNode tn = new TreeNode();
tn.Text = textBox1.Text.Trim();
treeView1.Nodes.Add(tn);
//添加選中的子節點:
treeView1.SelectedNode.Nodes.Add(tn);
//删除結點:
tn = treeView1.SelectedNode;
if (tn.Nodes.Count > 0)
{
DialogResult result = MessageBox.Show("該節點包含子節點,是否删除?\n确定請按是,取消請按否","删除提示",MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) tn.Remove();
}