A challenge(or maybe not) for Treeview Gurus 
Author Message
 A challenge(or maybe not) for Treeview Gurus

I'm trying to copy the nodes from one treeview control to another programmatically, like this:

Dim OldNode As Node
Dim NewNode As Node

NewTree.Nodes.Clear
For Each OldNode In OldTree.Nodes
 If OldNode = OldNode.Root Then
  Set NewNode = NewTree.Nodes.Add(, , OldNode.Key, OldNode.Text)
  Else
  Set NewNode = NewTree.Nodes.Add(OldNode.Parent.Key,tvwChild,OldNode.Key,OldNode.Text)
 End If
Next

The OldNode.Root entry adds properly, however, none of the child entries will add because I get the error "RunTime error # 35603 - Invalid Key".             HOW CAN THIS BE????

The "keys" exist properly in the original Tree. I have debugged and stepped through via IDE, and the entries from the initial tree are read in the correct order AND contain the right values.

Please Help, TIA

Robert R. Thele



Sat, 11 Nov 2000 03:00:00 GMT  
 A challenge(or maybe not) for Treeview Gurus

I'm trying to copy the nodes from one treeview control to another programmatically, like this:

Dim OldNode As Node
Dim NewNode As Node

NewTree.Nodes.Clear
For Each OldNode In OldTree.Nodes
 If OldNode = OldNode.Root Then
  Set NewNode = NewTree.Nodes.Add(, , OldNode.Key, OldNode.Text)
  Else
  Set NewNode = NewTree.Nodes.Add(OldNode.Parent.Key,tvwChild,OldNode.Key,OldNode.Text)
 End If
Next

The OldNode.Root entry adds properly, however, none of the child entries will add because I get the error "RunTime error # 35603 - Invalid Key".             HOW CAN THIS BE????

The "keys" exist properly in the original Tree. I have debugged and stepped through via IDE, and the entries from the initial tree are read in the correct order AND contain the right values.

Please Help, TIA

Robert R. Thele



Sat, 11 Nov 2000 03:00:00 GMT  
 A challenge(or maybe not) for Treeview Gurus

Michaela,

Quote:
> if oldNode = oldNode.root then

>only selects the very first item in your treeview unless there are some
>other items with the same TEXT !

That's exactly what I want this section of code to do; the "else" captures
all the remaining nodes. Unfortunately, I get the "invalid Key" message when
I try to add the remaining *child* nodes.

Still need help on this one...........

Rob

Quote:


>> I'm trying to copy the nodes from one treeview control to another =
>> programmatically, like this:

>> Dim OldNode As Node
>> Dim NewNode As Node

>> NewTree.Nodes.Clear
>> For Each OldNode In OldTree.Nodes
>>  If OldNode =3D OldNode.Root Then
>>   Set NewNode =3D NewTree.Nodes.Add(, , OldNode.Key, OldNode.Text)
>>   Else
>>   Set NewNode =3D =
>> NewTree.Nodes.Add(OldNode.Parent.Key,tvwChild,OldNode.Key,OldNode.Text)
>>  End If
>> Next

>Hi,

>I guess this is why :

> if oldNode = oldNode.root then

>only selects the very first item in your treeview unless there are some
>other items with the same TEXT !

>If you're trying to find items without a 'parent' ...

>  if oldNode.parent is nothing then

>should do the trick!

>Michaela



Sat, 11 Nov 2000 03:00:00 GMT  
 A challenge(or maybe not) for Treeview Gurus

Quote:

> I'm trying to copy the nodes from one treeview control to another =
> programmatically, like this:

> Dim OldNode As Node
> Dim NewNode As Node

> NewTree.Nodes.Clear
> For Each OldNode In OldTree.Nodes
>  If OldNode =3D OldNode.Root Then
>   Set NewNode =3D NewTree.Nodes.Add(, , OldNode.Key, OldNode.Text)
>   Else
>   Set NewNode =3D =
> NewTree.Nodes.Add(OldNode.Parent.Key,tvwChild,OldNode.Key,OldNode.Text)
>  End If
> Next

Hi,

I guess this is why :

 if oldNode = oldNode.root then

only selects the very first item in your treeview unless there are some
other items with the same TEXT !

If you're trying to find items without a 'parent' ...

  if oldNode.parent is nothing then

should do the trick!

Michaela



Sun, 12 Nov 2000 03:00:00 GMT  
 A challenge(or maybe not) for Treeview Gurus

I don't see how you can be sure that the parent node is already added when you try to add a child node. I suggest to make two loops.

    1) for each oldnode in oldtree.nodes
            if oldnode = oldnode.root then
                set newnode = newtree.nodes.add(, , oldnode.key, oldnode.text)
            else
                'do nothing
            end if
        next

    2) for each oldnode in oldtree.nodes
            if oldnode <> oldnode.root then
                set newnode = newtree.nodes.add(oldnode.parent.key, tvwchild, oldnode.key, oldnode.text)
            else
                'do nothing
            end if
        next

    I know this doesn't seem very good programming, but if this works your problem's solved not...



Sun, 12 Nov 2000 03:00:00 GMT  
 A challenge(or maybe not) for Treeview Gurus

Serge,
I do not quite understand what the difference is between your example and my original code. In my example, I perform the same tasks as you do in yours except that you use 2 "For" loops (I combine them in 1 loop.

As I stated in my original post, when I step through the code in the IDE, it appears that all the *old* nodes are being read as they should be. The *keys* to the new nodes are identical to the keys in the old nodes, however, I get that darned "Invalid Key" message (and yes, the keys start with an alphabetic character).

This problem is beyond me.........

Rob

        I don't see how you can be sure that the parent node is already added when you try to add a child node. I suggest to make two loops.

        1) for each oldnode in oldtree.nodes
                if oldnode = oldnode.root then
                    set newnode = newtree.nodes.add(, , oldnode.key, oldnode.text)
                else
                    'do nothing
                end if
            next

        2) for each oldnode in oldtree.nodes
                if oldnode <> oldnode.root then
                    set newnode = newtree.nodes.add(oldnode.parent.key, tvwchild, oldnode.key, oldnode.text)
                else
                    'do nothing
                end if
            next

        I know this doesn't seem very good programming, but if this works your problem's solved not...



Sun, 12 Nov 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. A challenge(or maybe not) for Treeview Gurus

2. Challenge - Maybe?

3. Challenge - maybe

4. challenging task? - maybe

5. Guru Challenge (Waveform Audio Files)

6. --> I challenge you VB guru!<--

7. Challenge to VB 3.0 / Access 2.0 guru: Creating new field of type Counter

8. A challenge for all the would-be gurus out there

9. A challenge for you VB gurus: Creating an independent copy of an object

10. Has anyone written...? CHALLENGE TO GURUs

11. Guru Challenge (Wav Audio Files)

12. APPBAR from VB (Guru Challenge)

 

 
Powered by phpBB® Forum Software