不知对不对????????
Private Sub Form_Load()
Dim nodx As Node
TreeView1.Style = tvwTreelinesPlusMinusPictureText
Set nodx = TreeView1.Nodes.Add(, , "id1", "张三")
nodx.Expanded = True
Set nodx = TreeView1.Nodes.Add("id1", tvwChild, "id1.1", "李四 ")
Set nodx = TreeView1.Nodes.Add("id1", tvwChild, "id1.2", "王二 ")
Set nodx = TreeView1.Nodes.Add("id1", tvwChild, "id1.3", "麻子")
nodx.Expanded = True
Set nodx = TreeView1.Nodes.Add("id1.3", tvwChild, "id1.3.1", "涨钱")
nodx.Expanded = True
Set nodx = TreeView1.Nodes.Add("id1.3.1", tvwChild, "id1.3.1.1", "顺利")
Set nodx = TreeView1.Nodes.Add("id1.3.1", tvwChild, "id1.3.1.2", "呼呼")
nodx.Expanded = True
End Sub
Private Sub Form_Load()
Dim nodx As Node
TreeView1.Style = tvwTreelinesPlusMinusPictureText
Set nodx = TreeView1.Nodes.Add(, , "id1", "张三")
nodx.Expanded = True
Set nodx = TreeView1.Nodes.Add("id1", tvwChild, "id1.1", "李四 ")
Set nodx = TreeView1.Nodes.Add("id1", tvwChild, "id1.2", "王二 ")
Set nodx = TreeView1.Nodes.Add("id1", tvwChild, "id1.3", "麻子")
nodx.Expanded = True
Set nodx = TreeView1.Nodes.Add("id1.3", tvwChild, "id1.3.1", "涨钱")
nodx.Expanded = True
Set nodx = TreeView1.Nodes.Add("id1.3.1", tvwChild, "id1.3.1.1", "顺利")
Set nodx = TreeView1.Nodes.Add("id1.3.1", tvwChild, "id1.3.1.2", "呼呼")
nodx.Expanded = True
End Sub
上述两个函数都可以很容易的实现。
如果是的话,可用以下的办法。
将数据库的中内容导入TreeStructure结构(代码略,注意导入时一定要将数据库的的内容按ID排升序后再给TreeStructure结构赋值。)
Private Type TreeStructure
Id As String
Name As String
End TypePrivate Sub Form_Load()
Dim i As Long, n As Integer, TempKey As String
Dim nodx As Node
TreeView1.Style = tvwTreelinesPlusMinusPictureTextFor i = LBound(m_stru) To UBound(m_stru)
n = InStrRev(m_stru(i).Id, ".")
If n = 0 Then
Set nodx = TreeView1.Nodes.Add(, , "key" + m_stru(i).Id, m_stru(i).Name)
nodx.Expanded = True
Else
TempKey = Left(m_stru(i).Id, n - 1)
Set nodx = TreeView1.Nodes.Add("key" + TempKey, tvwChild, "key" + m_stru(i).Id, m_stru(i).Name)
nodx.Expanded = True
End If
Next
End Sub