[英]Expand all parent nodes of a specific node in C# treeview
I'm creating a recursive find method in C# Treeview
, and I want to expand all parent nodes of the fined node. 我正在C#
Treeview
创建一个递归find方法,并且我想扩展罚款节点的所有父节点。 This is my code: 这是我的代码:
private void RecursivFindNode(RadTreeNodeCollection nodes, string nodeName2Find)
{
foreach (RadTreeNode node in nodes)
{
if (node.Text.Contains(nodeName2Find))
{
node.BackColor = Color.Yellow;
NodeExpand(node);
}
RecursivFindNode(node.Nodes);
}
}
private void NodeExpand(RadTreeNode nodeExpand)
{
while (nodeExpand != null)
{
nodeExpand.Expand();
nodeExpand = nodeExpand.Parent;
}
}
But I'm getting this error: 但我收到此错误:
Collection was modified; enumeration operation may not execute.
I know I can't modify the item which is in a foreach loop
. 我知道我无法修改
foreach loop
。 So how can I make it work? 那么我该如何运作呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.