设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1121|回复: 0
打印 上一主题 下一主题

[模块/函数] TREEVIEW关联问题

[复制链接]
跳转到指定楼层
1#
发表于 2011-8-16 12:20:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本人根据三小时掌握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
'* -----------------------------------------------------------------
'* 定义各类
'* -----------------------------------------------------------------


'设置最顶级的"爷"
'* ---------------------------
Set nodindex = TreeView.Nodes.Add(, , "A", "机电进出口公司")
nodindex.Sorted = True

'设置第二级"父"
'* ---------------------------
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

End Sub


在线等待高人指点...



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-30 05:47 , Processed in 0.100655 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表