呵呵,太复杂化了,这样应该就可以了(没有调试):
Private Sub TreeViewInitialize()
On Error Resume Next
TvwProductionSort.Nodes.Clear
TvwProductionSort.Nodes.Add , , "root", "商品类别", "pic1"
'rst设置
rst.movefirst
Do While Not rst.EOF
If IsNull(rst!商品部) = False Then TvwProductionSort.Nodes.Add "root", 4, rst!商品部, rst!商品部, "pic2"
If IsNull(rst!商品组) = False Then TvwProductionSort.Nodes.Add CStr(rst!商品部), 4, CStr(rst!商品部) & rst!商品组, rst!商品组, "pic3"
If IsNull(rst!商品类别) = False Then TvwProductionSort.Nodes.Add CStr(rst!商品部) & rst!商品组, 4, CStr(rst!商品部) & rst!商品组 & rst!商品类别, rst!商品类别, "pic4"
rst.MoveNext
Loop
Set rst = Nothing
End Sub
Private Sub TreeViewInitialize()
Dim Str_TmpNode As String
Dim Str_TmpNode2 As String
TvwProductionSort.Nodes.Clear
TvwProductionSort.Nodes.Add , , "root", "商品类别", "pic1"
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
GetRecordset rst, "select * from view_productionsort"
If Not (rst.EOF And rst.BOF) Then
rst.MoveFirst
Str_TmpNode = ""
Str_TmpNode2 = ""
str_tmpnode3 = ""
Do Until rst.EOF
If Str_TmpNode <> rst!商品部 Then
TvwProductionSort.Nodes.Add "root", 4, rst!商品部, rst!商品部, "pic2"
If IsNull(rst!商品组) = False And Str_TmpNode2 <> rst!商品组 Then
TvwProductionSort.Nodes.Add CStr(rst!商品部), 4, rst!商品组, rst!商品组, "pic3"
Str_TmpNode2 = rst!商品组
If IsNull(rst!商品类别) = False And str_tmpnode3 <> rst!商品类别 Then
TvwProductionSort.Nodes.Add CStr(rst!商品组), 4, rst!商品类别, rst!商品类别, "pic3"
str_tmpnode3 = rst!商品类别
End If
Else
If IsNull(rst!商品类别) = False And str_tmpnode3 <> rst!商品类别 Then
TvwProductionSort.Nodes.Add CStr(rst!商品组), 4, rst!商品类别, rst!商品类别, "pic3"
str_tmpnode3 = rst!商品类别
End If
End If
Else
If IsNull(rst!商品组) = False And Str_TmpNode2 <> rst!商品组 Then
TvwProductionSort.Nodes.Add CStr(rst!商品部), 4, rst!商品组, rst!商品组, "pic3"
Str_TmpNode2 = rst!商品组
If IsNull(rst!商品类别) = False And str_tmpnode3 <> rst!商品类别 Then
TvwProductionSort.Nodes.Add CStr(rst!商品组), 4, rst!商品类别, rst!商品类别, "pic3"
str_tmpnode3 = rst!商品类别
End If
Else
If IsNull(rst!商品类别) = False And str_tmpnode3 <> rst!商品类别 Then
TvwProductionSort.Nodes.Add CStr(rst!商品组), 4, rst!商品类别, rst!商品类别, "pic3"
str_tmpnode3 = rst!商品类别
End If
End If
End If
Str_TmpNode = rst!商品部
rst.MoveNext
Loop
End If
Set rst = Nothing
End Sub