如何从TreeNode.FullPath数据获取实际的treenode? [英] how to go from TreeNode.FullPath data and get the actual treenode?
本文介绍了如何从TreeNode.FullPath数据获取实际的treenode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想存储来自TreeNode.FullPath的一些数据,然后稍后我想重新扩展所有内容.有简单的方法吗?
I would like to store some data from TreeNode.FullPath and then later i would like to re-expand everything up to that point. Is there a simple way of doing it?
非常感谢!
推荐答案
您可以将其作为 TreeNodeCollection
的扩展方法编写:
You can write it as an extension method to the TreeNodeCollection
:
using System;
using System.Linq;
using System.Windows.Forms;
namespace Extensions.TreeViewCollection
{
public static class TreeNodeCollectionUtils
{
public static TreeNode FindTreeNodeByFullPath(this TreeNodeCollection collection, string fullPath, StringComparison comparison = StringComparison.InvariantCultureIgnoreCase)
{
var foundNode = collection.Cast<TreeNode>().FirstOrDefault(tn => string.Equals(tn.FullPath, fullPath, comparison));
if (null == foundNode)
{
foreach (var childNode in collection.Cast<TreeNode>())
{
var foundChildNode = FindTreeNodeByFullPath(childNode.Nodes, fullPath, comparison);
if (null != foundChildNode)
{
return foundChildNode;
}
}
}
return foundNode;
}
}
}
这篇关于如何从TreeNode.FullPath数据获取实际的treenode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文