TreeView parent syntax

The Stoat

The Grim Squeaker
Local time
Today, 01:09
Joined
May 26, 2004
Messages
239
Hi all,

I'm still having problems with the treeview control. I've found out from the microsoft knowledge base that you can't use numeric data for the nodes as the control treats them as variants and therefore tries to use them as indicies. This means you have to append something to them to make them a string and using the Cstr or str functions don't work either. :mad:

Anyway today's problem. If i have 2 parent nodes A,B

A has a child node F
B has a child node F

How do i add a child node to AF without it being added to BF?

Consider that i am populating this on the fly what syntax should the parent parameter take? I haven't managed to find any examples of this.


Code:
'Strparent = "A/F/" ? 
'StrChild = "X"

With MyTreeView.Node

     .add, Strparent,tvwChild,StrChild,StrChild

End With


Thanks for your help

TS
 
This is easier to solve than you think,

Your on the right track with cstr() and integer values, just place a character before the integer, ie

Strparent = "A" & Cstr(MyNum)

then if you need the number your can just chop the chr from the beginning

Ie

Mynum = cint(mid(strparent,2))


:cool:
 
Hi,

Thanks for the suggestion that is basically what i am doing with the [].

My real problem is i can't seem to add a childnode with the same name as another node (parent or child) even if it is in a different branch i.e Where G and H are childnodes of A and F is a child of G and another F is the child of H

--G----F
A
--H----F

This doesn't seem to be allowed!!


Any ideas??

thanks

TS
 
Stoat,

Each node requires a unique key and as such you cant have 2 nodes with the same key.

To get round this you could build the key from the ParentKey and the Child key,

Here is an example from a project i wrote ages ago...

Code:
Sub DispTreeView()
    Dim App As New AppointCls
    Dim Con As New AppointContactCls
    Dim OutApp As String
    Dim OutCon As String

    On Local Error Resume Next
    For Each App In AppointmentList
        
        OutApp = App.AppointmentDate & Space(5) & App.AppointmentTime & Space(5) & App.AppointmentActivityIDFK & Space(5) & App.AppointmentCO
        
        appTv.Nodes.Add , , "AID=" & App.AppointmentIDPK, OutApp, 2, 1

        For Each Con In App.Connacts
            OutCon = FLen(Con.PersonnelIDPK, 7) & Space(5) & FLen(Replace(Replace(Con.Title & Space(1) & Con.FirstName & Space(1) & Con.Inital & Space(1) & Con.Surname, "  ", " "), "  ", " "), 30)
            appTv.Nodes.Add "AID=" & App.AppointmentIDPK, tvwChild, "CID=" & App.AppointmentIDPK & ":" & Con.PersonnelIDPK, OutCon, 3
        Next

    Next
    On Local Error GoTo 0
End Sub

as you can see above it doesnt matter if teh same contact exists in multiple appointments as the key for the contact contains the appointment key, creating a unique Key for the child.

Hope this helps

:cool:
 
Last edited:
Hi Shadez,

I finally understand, I was just P****** around with it at it suddenly made sense, then i read your post and bingo there it was as well :D :D


The first Strchild is a unique identifer and is deemed to be a variant data type so if you use a number even though you've passed in a string data type variable it thinks your referencing the identifiers numeric index. Anyway, no matter what happens it must be unique.

The second StrChild can be anything numeric or string.

I'm going to have to take a pragmatic approach to creating the unqiue key as i don't actually need it for anything!

.add, Strparent,tvwChild,Strchild,StrChild

I was really wetting myself as this is a major work project that i'm just about to finish. I was doing the final tests when this sprung up. I've never used the control before and the documentation is lamentable.

Thanks for all your help

TS :p
 

Users who are viewing this thread

Back
Top Bottom