C#编程-55:TreeView控件复习笔记_彭世瑜_新浪博客
发布日期:2021-07-01 06:17:32 浏览次数:2 分类:技术文章

本文共 628 字,大约阅读时间需要 2 分钟。

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();
}

转载地址:https://pengshiyu.blog.csdn.net/article/details/109661765 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:C#编程-56:DatetimePicker复习笔记_彭世瑜_新浪博客
下一篇:C#编程-54:ListView控件复习笔记_彭世瑜_新浪博客

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月22日 00时21分17秒