treeview显示sql表数据的问题

wenti435 2005-04-01 12:07:11
在sql库中有这样一个表
01 a
0101 aa
0102 ab
0103 ac
02 b
0201 ba
0202 bb
0203 bc
................................
怎么样能显示在treeview下实现这种效果:
a
-aa
-ab
-ac
b
-ba
-bb
-bc
...............................
我比较菜,希望大家能给我解释清楚一点,谢谢
...全文
82 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cuilonggang 2005-04-01
  • 打赏
  • 举报
回复
用两个recordset,一个查询len(id)=2的,先添加到treeview中,然后用另一rs查询和这个id关联的,添加到treeview相应的下一级。
vb12345 2005-04-01
  • 打赏
  • 举报
回复
楼主是想只显示一个字段吧。
只导进一个字段不就行了吗?
wynbfqny 2005-04-01
  • 打赏
  • 举报
回复
还是不明白什么意思
XunBaian 2005-04-01
  • 打赏
  • 举报
回复
给你两个封装了TreeView的添加根节点和子节点的函数,Copy即可使用:


Public Sub AddRootNode(ByRef tvwTemp As TreeView, _
ByVal strKey As String, _
ByVal strText As String, _
Optional ByVal strImage As String = "", _
Optional ByVal strSelectedImage As String = "")

Dim nodTemp As Node

If strImage <> "" Then
If strSelectedImage <> "" Then
Set nodTemp = tvwTemp.Nodes.Add(, , strKey, strText, strImage, strSelectedImage)
Else
Set nodTemp = tvwTemp.Nodes.Add(, , strKey, strText, strImage)
End If
Else
Set nodTemp = tvwTemp.Nodes.Add(, , strKey, strText)
End If

Set nodTemp = Nothing

End Sub

Public Sub AddChildNode(ByRef tvwTemp As TreeView, _
ByVal strParentKey As String, _
ByVal strKey As String, _
ByVal strText As String, _
Optional ByVal strImage As String = "", _
Optional ByVal strSelectedImage As String = "")
On Error Resume Next
Dim nodTemp As Node

If strImage <> "" Then
If strSelectedImage <> "" Then
Set nodTemp = tvwTemp.Nodes.Add(strParentKey, tvwChild, strKey, strText, strImage, strSelectedImage)
Else
Set nodTemp = tvwTemp.Nodes.Add(strParentKey, tvwChild, strKey, strText, strImage)
End If
Else
Set nodTemp = tvwTemp.Nodes.Add(strParentKey, tvwChild, strKey, strText)
End If

Set nodTemp = Nothing

End Sub
wenti435 2005-04-01
  • 打赏
  • 举报
回复
我的意思是数据库中有一个表,表里面就两个字段,a,b,c,d,e等代表并列的父节点,aa,bb,cc,dd等则为响应的子节点,让他显示在treeview表中就行了。

cuilonggang() 麻烦你再说的详细点,我用len(id)=2添加了父节点后怎样添加对应的子节点啊?

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧