它似乎刪除TreeNode我必須遍歷它的父母,因此我做了下面只是爲了找到原始集合被修改,即使它是一個實例。下面是代碼和tvRightTree
感興趣收藏已修改;枚舉操作可能不會執行。 Treenode刪除
TreeNodeCollection checkedNodeCollection = tvRightTree.CheckedNodes;
foreach (TreeNode checkedNode in checkedNodeCollection) {
//if the to be removed node is parent then remove through treeview
if (checkedNode.Parent != null) {
//compiler does not allow modifying a collection that we iterate
//hence resort to finding the parent and then remove
TreeNode targetParent = tvRightTree.FindNode(checkedNode.Parent.ValuePath);
targetParent.ChildNodes.Remove(checkedNode);
} else
tvRightTree.Nodes.Remove(checkedNode);
}
什麼是從樹狀刪除選中的樹節點的正確方法TreeView的?