Solved

VB6 TreeView Nodes limit problem

Posted on 2004-04-09
6
2,238 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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