Private p_AdoCnn As New ADODB.Connection
Private p_AdoRS As New ADODB.Recordset
Public Function SetupMenu(ByRef vTreeView As TreeView) As Boolean
Dim o_Node As Node
Set o_Node = vTreeView.Nodes.Add(, , "root", "菜单内容设置", 1)
Set p_AdoRS = p_AdoCnn.Execute("select * from conttable ")
If Not p_AdoRS.EOF Then
With p_AdoRS
'.MoveLast
.MoveFirst
Do While Not .EOF
If Len(Trim(!contno)) = 1 Then
Set o_Node = vTreeView.Nodes.Add("root", tvwChild, "F" & !contno, !contno, 2)
Else
If Len(Trim(!contno)) = 2 Then
Set o_Node = vTreeView.Nodes.Add("root", tvwChild, "F" & Mid(Trim(!contno), 1, 1), Mid(Trim(!contno), 1, 1), 3)
Set o_Node = vTreeView.Nodes.Add("F" & Mid(Trim(p_AdoRS!contno), 1, 1), "S" & Mid(Trim(!contno), 2, 1), Mid(Trim(!contno), 2, 1), 2)
Else
Set o_Node = vTreeView.Nodes.Add("root", tvwChild, "F" & Mid(Trim(!contno), 1, 1), Mid(Trim(!contno), 1, 1), 3)
Set o_Node = vTreeView.Nodes.Add("F" & Mid(Trim(!contno), 1, 1), tvwChild, "S" & Mid(Trim(!contno), 2, 1), Mid(Trim(!contno), 2, 1), 3)
Set o_Node = vTreeView.Nodes.Add("S" & Mid(Trim(!contno), 2, 1), tvwChild, "T" & Mid(Trim(!contno), 3, 1), Mid(Trim(!contno), 3, 1), 2)
End If
End If
Loop
End With
End If
End Function
我用的是dao3.51,是书配盘的,你看看吧,(看别人的程序很麻烦的,所以我不会看你的程序了)
Tree.Nodes.Clear
While Not rs.EOF
Key = Trim$(rs!Key)
text = Trim(rs!Title)
Pos_t = InStr(Key, "f")
If Pos_t = 0 Then
Pos_t = InStr(Key, "e")
If Pos_t = 0 Then
Pos_t = InStr(Key, "d")
If Pos_t = 0 Then
Pos_t = InStr(Key, "c")
If Pos_t = 0 Then
Pos_t = InStr(Key, "b")
If Pos_t = 0 Then
Set nodex = Tree.Nodes.Add(, , Key, text)
nodex.Image = "nian"
nodex.EnsureVisible
Else
Set nodex = Tree.Nodes.Add(Left(Key, Pos_t - 1), 4, Key, text)
nodex.Image = "book"
End If
Else
Set nodex = Tree.Nodes.Add(Left(Key, Pos_t - 1), 4, Key, text)
nodex.Image = "file"
End If
Else
Set nodex = Tree.Nodes.Add(Left(Key, Pos_t - 1), 4, Key, text)
nodex.Image = "file"
End If
Else
Set nodex = Tree.Nodes.Add(Left(Key, Pos_t - 1), 4, Key, text)
nodex.Image = "file"
End If
Else
Set nodex = Tree.Nodes.Add(Left(Key, Pos_t - 1), 4, Key, text)
nodex.Image = "file"
End If
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing