It seems for removing a TreeNode i have to traverse to it's parent hence i did below just to find the original collection was modified even though it was a instance. Below is the code and tvRightTree
is the TreeView of interest
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);
}
What is the correct way to remove checked TreeNodes from the treeview?