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]
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
