断点调试一下,看看 LoadNextNodes 被执行到哪一层出现的问题。很有可能是一些特殊结点的存在,导致错误的发生,例如叶子结点。以上猜测,就当帮你 up 。

解决方案 »

  1.   


    Private Const csTreeRoot As String = "xxx Tech Co."
    Private Sub Form_Load()
        RefreshCategory
    End Sub
    Private Sub RefreshCategory()
        Dim oNode As Node
        With trv
            .Nodes.Clear
            .Style = tvwTreelinesPlusMinusPictureText
            .Sorted = True
            .LabelEdit = tvwManual
            Set oNode = .Nodes.Add(, , csTreeRoot, csTreeRoot)
        End With    SearchCategory 0, csTreeRoot
        trv.Nodes(1).Expanded = True
        
    End Sub
    Private Function SearchCategory(ByVal lOutParentID As Long, ByVal sNode As String) As Boolean
        Dim oRead As New CDBFetch
        Dim oRS As ADODB.Recordset
        Dim oNode As Node
        Dim sCategory As String
        Dim lID As Long
        Dim lParentID As Long
        
        
        Set oRS = oRead.GetDepartmentList("ParentID=" & lOutParentID, "Name ASC")
        If oRS Is Nothing Then Exit Function
            
        With oRS
            If .EOF = True And .BOF = True Then
                Exit Function
            Else
                .MoveFirst
                While Not .EOF
                    sCategory = .Fields("Name").Value
                    lID = .Fields("ID").Value
                    Set oNode = trv.Nodes.Add(sNode, tvwChild, sCategory & lID, sCategory)
                    SearchCategory lID, sCategory & lID
                    oNode.Tag = lID
                    oNode.Expanded = True
                    .MoveNext
                Wend
            End If
        End With
    End Function
      

  2.   

    最好是先将一级节点添加完成再添加下一级节点!
    也就是一级一级来。在一个记录集的循环中最后不要跳出去执行下一个对记录集的调用中。就像你的LoadNextNodes函数!