如何遍历WINFORM的TREEVIEW的所有节点
2个回答
展开全部
public Form1()
{
InitializeComponent();
//遍历节点获取节点名
foreach (TreeNode tn in treeView1.Nodes)
{
getTreeNodeName(tn);
}
}
private void getTreeNodeName(TreeNode tn)
{
//将当前节点名显示到lable上
label1.Text += "name:"+ tn.Text + "\r\n";
//遍历节点的子节点
foreach (TreeNode tnSub in tn.Nodes)
{
getTreeNodeName(tnSub);
}
}
{
InitializeComponent();
//遍历节点获取节点名
foreach (TreeNode tn in treeView1.Nodes)
{
getTreeNodeName(tn);
}
}
private void getTreeNodeName(TreeNode tn)
{
//将当前节点名显示到lable上
label1.Text += "name:"+ tn.Text + "\r\n";
//遍历节点的子节点
foreach (TreeNode tnSub in tn.Nodes)
{
getTreeNodeName(tnSub);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询