Solved

VB6 TreeView Nodes limit problem

Posted on 2004-04-09
6
2,197 Views
Last Modified: 2013-12-26
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
Comment
Question by:jayleno
  • 3
  • 3
6 Comments
 
LVL 27

Accepted Solution

by:
Dabas earned 250 total points
ID: 10796349
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
 

Author Comment

by:jayleno
ID: 10805911
Thanks Dabas!  It works.
0
 

Author Comment

by:jayleno
ID: 10816347
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Expert Comment

by:Dabas
ID: 10816431
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
 

Author Comment

by:jayleno
ID: 10816543
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
 
LVL 27

Expert Comment

by:Dabas
ID: 10818461
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now