我想存储 TreeNode.FullPath 中的一些数据,然后我想重新扩展到目前为止的所有内容。有简单的方法吗?
多谢!
您可以将其编写为扩展方法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;
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)