我有以下功能用于搜索 Treeview:
public static TreeNode FindAllNamesInTreeView(TreeView treeView, String name, int StartNode = -1, bool Searchilds = true)
{
TreeNode newNode = new TreeNode("SRes");
newNode.Nodes.Add("Test");
// check if we have a treeview
if (treeView == null)
return null;
// iterate through the treeview's root nodes
for (int i = 0; i < treeView.Nodes.Count; i++)
{
// for each root node try to find the node with the name we want
TreeNode foundNode = FindNameInTreeView(treeView.Nodes[i], name, StartNode, Searchilds);
// if we found the node, return it
if (foundNode != null)
if (TheIndexOf(foundNode) > StartNode)
newNode.Nodes.Add( foundNode); //Error here!
}
// no node found
return newNode;
}
在执行 newNode.Add(foundNode); 我有以下例外:
'System.Windows.Forms.dll 中出现'System.ArgumentException' 类型的第一次机会异常'
谁能告诉我出了什么问题或如何将收集到的所有节点添加到此处?