how to find child nodes at root node [TreeView](如何在根节点找到子节点 [TreeView])
问题描述
ROOT
A
B
C
D
E
T
F
G
X
我想找到 E 节点的父节点(编号为 5).然后,我将保存节点.如果数字小于 5.我在 Asp.net 控件中使用 TreeView.
I want to find E Node's parent nodes(it is number 5). Then, I'll save node. If number is smaller 5. I'm using TreeView in Asp.net control.
推荐答案
我建议使用递归迭代.
private TreeNode FindNode(TreeView tvSelection, string matchText)
{
foreach (TreeNode node in tvSelection.Nodes)
{
if (node.Tag.ToString() == matchText)
{
return node;
}
else
{
TreeNode nodeChild = FindChildNode (node, matchText);
if (nodeChild != null) return nodeChild;
}
}
return (TreeNode)null;
}
您可以利用此逻辑来确定关于您的节点的许多事情,并且此结构还允许您扩展您可以对节点执行的操作以及您希望搜索的条件.您可以编辑我的示例以满足您自己的需要.
You can utilize this logic to determine many things about you node and this structure also allows you to expand what you can do with the node and the criteria you wish to search for. You can edit my example to fit your own needs.
因此,在这个例子中,你可以传入 E 并期望返回节点 E 然后简单地如果返回的节点的父属性将是您所追求的父.
Thus, with this example you could pass in E and expect to have the node E returned then simply if the parent property of the node returned would be the parent you are after.
tn treenode = FindNode(myTreeview, "E")
tn.parent 是您所追求的值.
这篇关于如何在根节点找到子节点 [TreeView]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在根节点找到子节点 [TreeView]
基础教程推荐
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 如果条件可以为空 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
