I am looking for a quicker way to get a list of Checked Nodes.
Right now I am using a For Each Node As UltraTreeNode in TreeNodeCollection
But if there are a thousand nodes in the tree this takes a long time. Loop after loop if each node has children.
I have 2 states a single Check tree where a checked node does not effect the parent and a TriState tree.
Here is my current code:
(This takes in a collection and loops through,
CurrentIdList is a list of Checked Id's that has been passed in, if a node exists in the tree and is no longer checked then remove it from the list.
Me._toolBarStyle.MultipleChecks = False means a single check tree)
Private Sub GetCheckedIDs(ByVal treeNodeList As Infragistics.Win.UltraWinTree.TreeNodesCollection, ByVal Remove As Boolean
)
Then
treeNodeList
CurrentIdList.Remove(Format.NullSafeDecimal(treeNode.Key))
Else
CurrentIdList.Add(Format.NullSafeDecimal(treeNode.Key))
If
GetCheckedIDs(treeNode.Nodes,
Next
Sub
Unfortunately the code is unreadable because of the formatting, but I was able to see that in addition to querying the node's checked state, you are also using the Contains method of 'CurrentIdList'. This could be what is making the search expensive; the Contains method typically does a linear search through the entire list, so if the search condition fails, the Contains method implementation will have checked every item in the list. The amount of time this takes increases proportionally to the size of the list, which grows each time the search succeeds. You might want to use a dictionary instead, which uses a hashing algoritm to make the comparison rather than brute force.