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.
Does this mean there is no easy way to retrieve a Checked Nodes list? The only way is to loop through the Nodes and look at the CheckedState property?
Um.. I'm pretty sure the tree already has SelectedNodes. :)
Oh... One request for a new feature coming right up! We need a SelectedNodes and CheckedNodes collection of the Nodes property ;o)
The tree doesn't keep a list, so you either have to loop or keep track of the checked nodes yourself.
If you have a lot of nodes, I would not use a loop, since this could end up being pretty inefficient. I think keeping track of the checking and unchecking of the nodes and maintaining a List<T> or a Dictionary would be a better way to go.