Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
List of Checked Nodes
posted

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

)

 

 

If treeNodeList IsNot Nothing

Then

 

 

For Each treeNode As UltraTreeNode In

treeNodeList

 

 

If Remove

Then

 

 

If CurrentIdList.Contains(Format.NullSafeDecimal(treeNode.Key)) Then

CurrentIdList.Remove(Format.NullSafeDecimal(treeNode.Key))

 

 

Else

 

 

If treeNode.CheckedState = CheckedStatus.Checked

Then

 

 

If Not CurrentIdList.Contains(Format.NullSafeDecimal(treeNode.Key)) Then

CurrentIdList.Add(Format.NullSafeDecimal(treeNode.Key))

 

 

Else

 

 

If CurrentIdList.Contains(Format.NullSafeDecimal(treeNode.Key)) Then

CurrentIdList.Remove(Format.NullSafeDecimal(treeNode.Key))

 

 

End

If

 

 

End

If

 

 

If treeNode.Nodes IsNot Nothing AndAlso treeNode.Nodes.Count > 0

Then

 

 

If Not treeNode.CheckedState = CheckedStatus.Checked

Then

GetCheckedIDs(treeNode.Nodes,

 

False

)

 

 

Else

 

 

If Me._toolBarStyle.MultipleChecks

Then

GetCheckedIDs(treeNode.Nodes,

 

True

)

 

 

Else

GetCheckedIDs(treeNode.Nodes,

 

False

)

 

 

End

If

 

 

End

If

 

 

End

If

 

 

Next

 

 

End

If

 

 

End

Sub

Parents
  • 69832
    Suggested Answer
    Offline posted

    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.

Reply Children