Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2370
  • Last Modified:

VB6 TreeView Nodes limit problem

Hi,

I have a VB6 TreeView control in my VB6 application, and I need to load a lot of data into the tree, say 50,000 nodes.  The treeview was able to load all 50,000 nodes all right - although very slow - and the nodes show up in the tree.  The problem is, when I iterate through the nodes like this:

Dim Nodes As MSComctlLib.Nodes, curNode As MSComctlLib.Node
Dim i As Long

Set Nodes = MyTree.Nodes
For i = 1 To Nodes.count
      Set curNode = Nodes.Item(i)
      If curNode.children > 0 Then
           ' Do some thing with the node
      End If
Next

The Nodes.count will be a negative -27536 when actually there are 50,000 node in the treeview.  It seems like there is a limit to Nodes.count that you cannot exceed, and the iteration in the code above won't work.

Do anyone has a solution to my problem?

Thanks for your help.
0
jayleno
Asked:
jayleno
  • 3
  • 3
1 Solution
 
DabasCommented:
Hi jayleno:
Bugger!
If you look up Nodes.Count in Object Browser, you will see that it is defined as Integer!
This explains your problem, but does not provide the solution.

I would suggest you iterate through the tree using Node.Next instead of using the For loop.

Something like

Dim curNode as Node
Set curNode = MyTree.Nodes.Item(1) 'First node
While not curNode is Nothing
    If curNode.Children > 0 then
        'Do something
    End If
    Set curNode = curNode.Next
Wend

Dabas
0
 
jaylenoAuthor Commented:
Thanks Dabas!  It works.
0
 
jaylenoAuthor Commented:
Hi Dabas,

A few more words.  Using Node.Next to iterate through the tree works, but it's still a much easier and cleaner iteration using the For loop and Nodes.count.  Because depending on the tree structure, it can be a lot more work to iterate through every node in the tree using Node.Next.  Sure hope the Nodes.count can be something bigger than a integer!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
DabasCommented:
jayleno:
You might have a point, but I will have to disagree with part of it:
1) The documentation describes Nodes.count as an integer, which as you point out is stupid. Silly M$! I just checked in VB.NET, and there Nodes.Count ALSO is an integer... only in .NET and integer is the same as a long in VB6

2) Easier and cleaner?
One says
For i = 1 to TreeView1.Nodes.Count -1

Next

While not curNode is Nothing
      If....

      Else
Wend

So there is an extra IF there.... I do not think that it makes the iteration that much easier either, and it overcomes the Integer limitation!

Dabas
0
 
jaylenoAuthor Commented:
Dabas,

No, what I meant by "depending on the tree structure, it can be a lot more work to iterate through every node in the tree using Node.Next" is, the tree can have multiple levels, and when one just does Set curNode = curNode.Next you are only iterating through one level of the tree.  Of course you want to go through all top level node, the node on the next level, ..., until you get to the bottom level.  It does't have to be in that order, but you have to manage to traverse all the nodes in the tree, not just some, and using the indexes by using Nodes.Count makes it easier.  Using Set curNode = curNode.Next you have to go through all parents and children.  It can be done, just more work.  But you get my drift.
0
 
DabasCommented:
jayleno,
Your original code also seems to handle children separately.
If you really have to traverse through all nodes, and not just one level, then recursion is very effective...
It might also solve your integer problem, if the amount of nodes at a particular level do not cross the integer boundary

Dabas
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now