Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TreeView and Adding Parent Nodes
Message
From
18/06/2002 14:16:48
Jason Dalio
Northern Interior Regional Health Board
Prince George, British Columbia, Canada
 
 
To
All
General information
Forum:
Visual Basic
Category:
ActiveX controls
Title:
TreeView and Adding Parent Nodes
Miscellaneous
Thread ID:
00669841
Message ID:
00669841
Views:
29
I'm using TreeView for the first time and while I have everything working properly I ahve a nagging irritation about how I am doing something. I need to dynamically add Categories (parents) and Category types (children). I am adding them like this:
Dim nodx As Node

    On Error GoTo errHandler:
    
    Set CNLoadData = CreateObject("ADODB.Connection")
    Set RSLoadData = CreateObject("ADODB.Recordset")
    
    CNLoadData.ConnectionString = ConnectionString
    CNLoadData.Open
    
    SQLString = "SELECT ProgressNotes.*, Staff.*, Discipline.* FROM ProgressNotes INNER JOIN " & _
        "Staff ON " & _
        "(ProgressNotes.StaffID = Staff.StaffID) " & _
        "INNER JOIN Discipline ON " & _
        "(Staff.DisciplineID = Discipline.DisciplineID) " & _
        "WHERE ProgressNotes.ClientID = " & CurrentClientID & _
        " ORDER BY Discipline.DisciplineDesc, Staff.LastName, Staff.FirstName, " & _
        "ProgressNotes.ProgressNoteDate;"
    RSLoadData.Open (SQLString), CNLoadData, adOpenForwardOnly, adLockReadOnly
    With RSLoadData
        Do Until .EOF
            Set nodx = trvProgressNotes.Nodes.Add(CStr(RSLoadData.Fields("DisciplineDesc")) _
                , tvwChild, "PNID" & RSLoadData.Fields("ProgressNoteID"), _
                RSLoadData.Fields("ProgressNoteDate") & " : " & _
                RSLoadData.Fields("LastName") & ", " & RSLoadData.Fields("FirstName"))
            RSLoadData.MoveNext
        Loop
    End With
        
    GoSub CleanupADODB
    Exit Sub

CleanupADODB:
    RSLoadData.Close
    Set RSLoadData = Nothing
    CNLoadData.Close
    Set CNLoadData = Nothing
    Return
    Exit Sub
    
errHandler:
    If Err = 35601 Then 'Parent node does not currently exist so add it
        Set nodx = trvProgressNotes.Nodes.Add(, , _
            RSLoadData.Fields("DisciplineDesc"), _
            RSLoadData.Fields("DisciplineDesc"))
        Resume
    End If
Essentially I try and add a child. If no parent exists then an error is raised and a parent is entered and then the code resumes, entering the child. This works but it is a real pain when I need to debug other code in Break On All Errors. Scanning the whole tree each time before adding a child though seems like a waste of resources. Suggestions?
Next
Reply
Map
View

Click here to load this message in the networking platform