标题: 菜鸟请教一TREEVIEW问题 [打印本页] 作者: aioliadl 时间: 2011-8-16 11:13 标题: 菜鸟请教一TREEVIEW问题 本人根据三小时掌握treeview来学习制作一树形查询,左边是treeview,右边是liveview。目的是用户从左侧树形结构中点击相应的选项后,右边liveview中显示该选择的相应详细信息,但本人始终没有实现。本人不懂代码,勿笑话哈,在线等待高人解决!
根据三小时的编写的代码如下:
Private Sub Form_Load()
'* -----------------------------------------------------------------
'* 用数据库表(查询也一样)中数据填充树控件
'* -----------------------------------------------------------------
Dim Rec As New ADODB.Recordset
Dim stRecQL As String
Dim Item As Integer
Dim i As Integer
Dim nodindex As Node
'* -----------------------------------------------------------------
'* 定义各类
'* -----------------------------------------------------------------
'设置第二级"父"
'* ---------------------------
Rec.Open "1", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdTableDirect
For i = 0 To Rec.RecordCount - 1
Set nodindex = TreeView.Nodes.Add("A", tvwChild, "B" & Rec.Fields("部门代码"), Rec.Fields("部门名称"))
nodindex.Sorted = True
Rec.MoveNext
Next
Rec.Close
'设置第三级"子"
'* ---------------------------
Rec.Open "2", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdTableDirect
For i = 0 To Rec.RecordCount - 1
Set nodindex = TreeView.Nodes.Add("B" & Rec.Fields("所属部门"), tvwChild, "C" & Rec.Fields("部门代码"), Rec.Fields("部门名称"))
nodindex.Sorted = True
Rec.MoveNext
Next
Rec.Close
'* 设置第四级"孙"
'* ---------------------------
Rec.Open "表1", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdTableDirect
For i = 0 To Rec.RecordCount - 1
Set nodindex = TreeView.Nodes.Add("C" & Rec.Fields("部门"), tvwChild, "C" & Rec.Fields("工号"), Rec.Fields("姓名"))
nodindex.Sorted = True
Rec.MoveNext
Next
Rec.Close
End Sub
Private Sub Treeview_NodeClick(ByVal Node As Object)
'* -----------------------------------------------------------------
'*树控件的鼠标点击事件为NodeClick
'* -----------------------------------------------------------------
Dim str As String
'* -----------------------------------------------------------------
'*定义一个筛选
'* -----------------------------------------------------------------
If Node.Text = "机电进出口公司" Or Node.Key Like "B*" Or Node.Key Like "C*" Then
str = ""
Else
str = "[姓名]='" & Node.Text & "'"
End If
Me.Form.FilterOn = True
Me.Form.Filter = str