c# - How to Efficiently Delete Checked Items from a TreeView? -


Can check how easily one can walk through all the nodes in a tree view. Remove checked assets and then all check nodes?

It seems straightforward, but you do not want to modify a collection through which you are repetitive, so that the possibility of "foreach" loop will be lost. (.node is modifying call collections.) If this is tried, the effect is that only about half is closer. Check nodes are removed.

Even if someone is using two passes: First, make a list of temporary indexes, and then remove by the other nearby index - the index will change on each deletion, inventing the integrity of the index list.

So, what is the most effective way to do this?

Here is an example of a code that looks good, but actually only removes half from it. Check nodes

foreach (TriNode guardian in treeView.NOD) {if (parent.Checked) {treeView.Nodes.Remove (parent); } Else {foreach (parent.node to parent.Nodes) {if (child.Checked) parent.Nodes.Remove (child); }}}

(Yes, its purpose is to sprinkle the nodes with only one tree which is two levels deep.)

This will remove the nodes after enumerating, and can be used again for nodes of nodes.

Zero Deleted Check Nodes (tree nodecollection nodes) {List & lt; Trioode & gt; CheckNodes = New list & lt; TreeNode & gt; (); Fresh (tree node node in nodes) {if (node ​​check) {checkedNodes.Add (node); } And {RemoveClide Nodes (Nodes. ChildNodes); }} Foreach (Nodes in checknod check node) {nodes. Remove (checknod); }}

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -