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);
//添加选中的子节点:
if (textBox1.Text.Trim() == "") return;
TreeNode tn = new TreeNode();
tn.Text = textBox1.Text.Trim();
treeView1.SelectedNode.Nodes.Add(tn);
//删除结点:
TreeNode tn = new TreeNode();
tn = treeView1.SelectedNode;
if (tn.Nodes.Count > 0)
{
DialogResult result = MessageBox.Show("该节点包含子节点,是否删除?\n确定请按是,取消请按否","删除提示",MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) tn.Remove();
}