当前位置:编程学习 > VB >>

关于VB中的树型列表,一段代码,不是很懂,哪位大侠帮解释下?谢谢!

' ******************************************************************************
'过程名:viewDataDep
'说  明:将部门信息显示在树型列表中, 其中编码规则为一级部门**000000,二级部门****0000,三级部门******00
'参  数:无
'返回值:无
' ******************************************************************************
Private Sub viewDataDep()
Dim i As Integer
On Error GoTo View_Error
'检索部门信息显示在树型列表中
Me.trvDep.Nodes.Clear
txtSQL = "select DepId ,DepName ,Describe from tbDep order by DepId"
results = ExecuteSQL(txtSQL, rstDep, False)
If rstDep.RecordCount <> 0 Then
    For i = 0 To rstDep.RecordCount - 1
        If StrComp(Mid(rstDep.Fields(0), 3, 4), "0000") = 0 Then
            Set nodeDep = trvDep.Nodes.Add(, , "dep" + Left(rstDep.Fields(0), 2), _
            rstDep.Fields(1))
        Else
            If StrComp(Mid(rstDep.Fields(0), 5, 2), "00") = 0 Then
              Set nodeDep = trvDep.Nodes.Add("dep" + Left(rstDep.Fields(0), 2), _
              tvwChild, "dep" + Left(rstDep.Fields(0), 4), rstDep.Fields(1))
            Else
              Set nodeDep = trvDep.Nodes.Add("dep" + Left(rstDep.Fields(0), 4), _
              tvwChild, "dep" + Left(rstDep.Fields(0), 6), rstDep.Fields(1))
            End If
        End If
        rstDep.MoveNext
    Next
Else
    MsgBox "没有部门信息!", vbOKOnly + vbExclamation, "警告"
End If
Exit Sub
View_Error:
  MsgBox "部门编号输入有误,请检查数据库并修正记录!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End Sub
--------------------编程问答-------------------- 主要是if语句以后的那些代码,不是很懂啊! --------------------编程问答-------------------- 真挫,这代码


如果添加一个子节点,其父节点没有加载的话,就出错了,树结构用递归是最简洁高效的 --------------------编程问答-------------------- 看不懂就删掉自己写一个。

这个代码真的很挫。
补充:VB ,  网络编程
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,