字段名: guo sheng shi
中国 黑龙江省 哈尔滨
中国 黑龙江省 齐齐哈尔
中国 黑龙江省 牡丹江
中国 云南省 昆明
中国 云南省 个旧
(外国)(州、省) ....
.... .... ....
.... .... ....
如何将上面的记录通过程序读到一个TreeView控件中,
要求第一级是*名称,第二级是省、州级名称,第三级是市级名称。
也就是如果国家名称一样的,都在一级里,点击TreeView控件中的“+”时,显示这个国家的省、州一级的名称。如果再点击省、州一级名称前面的“+”时,则显示这个省或州的市一级的名称。
不知我的意思大家是否明白,知道的请一定帮忙!
14 个解决方案
#1
可以!easy
建议一次只展开一级!
建议一次只展开一级!
#2
同上
#3
http://www.wzjcw.net/vbgood/taishan/index.html
【迷你数据库浏览器】源代码。
【迷你数据库浏览器】源代码。
#4
首先是建立一级目录,把字段guo中的记录分组,然后一个一个加上去,然后给每个
节点下加一个临时节点(由于国家节点现在是隐藏的,临时节点用户看不到)。当发生节点展开事件时,获得节点的标题,删除其下的临时节点,然后根据标题查询guo字段等于标题的记录,将记录按sheng字段分组,分别添加到展开的国家节点下面。shi节点的做法同上。
节点下加一个临时节点(由于国家节点现在是隐藏的,临时节点用户看不到)。当发生节点展开事件时,获得节点的标题,删除其下的临时节点,然后根据标题查询guo字段等于标题的记录,将记录按sheng字段分组,分别添加到展开的国家节点下面。shi节点的做法同上。
#5
Set Nodx = TreeView1.Nodes.Add(, , "firstchild", "国家名称")
Nodx.Image = 1
RsBook.Open "select distinct guo from 表", cn, adOpenForwardOnly, adLockReadOnly
If Not RsBook.BOF Then RsBook.MoveFirst
Do Until RsBook.EOF
Set Nodx = TreeView1.Nodes.Add("firstchild", tvwChild, "children" & r, RsBook.Fields("guo"))
Nodx.Image = 2
RsBanben.Open "select distinct sheng from 表 where guo='" & RsBook(0).Value & "'", cn, adOpenForwardOnly, adLockReadOnly
If RsBanben.EOF = False And RsBanben.BOF = False Then
Do Until RsBanben.EOF
Set Nodx = TreeView1.Nodes.Add("children" & r, tvwChild, "schildren" & j, RsBanben.Fields("sheng"))
Nodx.Image = 3
Rspic.Open "select distinct shi from 表 where guo='" & RsBook(0).Value & "'" & " and " & "sheng='" & RsBanben(0).Value & "'", cn, adOpenForwardOnly, adLockReadOnly
If Rspic.EOF = False And Rspic.BOF = False Then
Do Until Rspic.EOF
Set Nodx = TreeView1.Nodes.Add("schildren" & j, tvwChild, "Tchildren" & k, Rspic.Fields("shi"))
Nodx.Image = 4
k = k + 1
Rspic.MoveNext
Loop
End If
Rspic.Close
j = j + 1
RsBanben.MoveNext
Loop
End If
RsBanben.Close
r = r + 1
RsBook.MoveNext
Loop
RsBook.Close
这是我以前的例子经改动后,不知能看懂?
能看懂的话给小妹加点分
Nodx.Image = 1
RsBook.Open "select distinct guo from 表", cn, adOpenForwardOnly, adLockReadOnly
If Not RsBook.BOF Then RsBook.MoveFirst
Do Until RsBook.EOF
Set Nodx = TreeView1.Nodes.Add("firstchild", tvwChild, "children" & r, RsBook.Fields("guo"))
Nodx.Image = 2
RsBanben.Open "select distinct sheng from 表 where guo='" & RsBook(0).Value & "'", cn, adOpenForwardOnly, adLockReadOnly
If RsBanben.EOF = False And RsBanben.BOF = False Then
Do Until RsBanben.EOF
Set Nodx = TreeView1.Nodes.Add("children" & r, tvwChild, "schildren" & j, RsBanben.Fields("sheng"))
Nodx.Image = 3
Rspic.Open "select distinct shi from 表 where guo='" & RsBook(0).Value & "'" & " and " & "sheng='" & RsBanben(0).Value & "'", cn, adOpenForwardOnly, adLockReadOnly
If Rspic.EOF = False And Rspic.BOF = False Then
Do Until Rspic.EOF
Set Nodx = TreeView1.Nodes.Add("schildren" & j, tvwChild, "Tchildren" & k, Rspic.Fields("shi"))
Nodx.Image = 4
k = k + 1
Rspic.MoveNext
Loop
End If
Rspic.Close
j = j + 1
RsBanben.MoveNext
Loop
End If
RsBanben.Close
r = r + 1
RsBook.MoveNext
Loop
RsBook.Close
这是我以前的例子经改动后,不知能看懂?
能看懂的话给小妹加点分
#6
select guo from T Group by guo
select sheng from T where guo ='TreeView的某节点' Group by sheng
select shi from T where guo ='TreeView的某国节点' and sheng='guo ='TreeView的某省节点' Group by shi
select sheng from T where guo ='TreeView的某节点' Group by sheng
select shi from T where guo ='TreeView的某国节点' and sheng='guo ='TreeView的某省节点' Group by shi
#7
select guo from T Group by guo
select sheng from T where guo ='TreeView的某节点' Group by sheng
select shi from T where guo ='TreeView的某国节点' and sheng='TreeView的某省节点' Group by shi
select sheng from T where guo ='TreeView的某节点' Group by sheng
select shi from T where guo ='TreeView的某国节点' and sheng='TreeView的某省节点' Group by shi
#8
这里不好说,给我你的信箱,我给你发一个过去。
#9
程序如下:
Dim con As New ADODB.Connection
Dim recGuo As New ADODB.Recordset
Dim recSheng As New ADODB.Recordset
Dim recShi As New ADODB.Recordset
'打开库连接
con.Open .....
'先读取国信息
recGuo.Open "select distinct guo from table", con, adOpenStatic, adLockOptimistic
Do Until recGuo.EOF
'向TreeView中添加国名
TreeView.Nodes.Add , , recGuo.Fields("guo"), recGuo.Fields("guo"), 1
'读取此国下的省信息
recSheng.Open "select sheng from table where guo='" & recGuo.Fields("guo") & "'", con, adOpenStatic, adLockOptimistic
Do Until recSheng.EOF
'向TreeView中添加省名
TreeView.Nodes.Add recGuo.Fields("guo"), tvwChild, recSheng.Fields("sheng"), recSheng.Fields("sheng"), 2
'读取此省下的市信息
recShi.Open "select shi from table where guo='" & recGuo.Fields("guo") & "' and sheng='" & recSheng.Fields("sheng") & "'", con, adOpenStatic, adLockOptimistic
Do Until recShi.EOF
'向TreeView中添加市名
Set treNode = TreeView.Nodes.Add(recSheng.Fields("sheng"), tvwChild, recShi.Fields("shi"), recShi.Fields("shi"), 3)
recShi.MoveNext
Loop
recPufferTemp.MoveNext
Loop
Loop
recShi.Close
recSheng.Close
recGuo.Close
Set recShi = Nothing
Set recSheng = Nothing
Set recGuo = Nothing
Dim con As New ADODB.Connection
Dim recGuo As New ADODB.Recordset
Dim recSheng As New ADODB.Recordset
Dim recShi As New ADODB.Recordset
'打开库连接
con.Open .....
'先读取国信息
recGuo.Open "select distinct guo from table", con, adOpenStatic, adLockOptimistic
Do Until recGuo.EOF
'向TreeView中添加国名
TreeView.Nodes.Add , , recGuo.Fields("guo"), recGuo.Fields("guo"), 1
'读取此国下的省信息
recSheng.Open "select sheng from table where guo='" & recGuo.Fields("guo") & "'", con, adOpenStatic, adLockOptimistic
Do Until recSheng.EOF
'向TreeView中添加省名
TreeView.Nodes.Add recGuo.Fields("guo"), tvwChild, recSheng.Fields("sheng"), recSheng.Fields("sheng"), 2
'读取此省下的市信息
recShi.Open "select shi from table where guo='" & recGuo.Fields("guo") & "' and sheng='" & recSheng.Fields("sheng") & "'", con, adOpenStatic, adLockOptimistic
Do Until recShi.EOF
'向TreeView中添加市名
Set treNode = TreeView.Nodes.Add(recSheng.Fields("sheng"), tvwChild, recShi.Fields("shi"), recShi.Fields("shi"), 3)
recShi.MoveNext
Loop
recPufferTemp.MoveNext
Loop
Loop
recShi.Close
recSheng.Close
recGuo.Close
Set recShi = Nothing
Set recSheng = Nothing
Set recGuo = Nothing
#10
我的Email:songzj198@0451.com
#11
If dars.State = adStateOpen Then dars.Close
sql = "select * from da "
dars.Open sql, cn, adOpenKeyset, adLockBatchOptimistic
Do While Not dars.EOF
'大类节点KEY为"DA"+rs("大类序号")
Set nodx = TreeView1.Nodes.Add(, , "DA" + Trim(dars(0)), Trim(dars(1)), 2, 1)
sql = "select * from xiao where 大类序号=" & CInt(dars(0))
If xiaors.State = adStateOpen Then xiaors.Close
xiaors.Open sql, cn, adOpenKeyset, adLockBatchOptimistic
For I = 1 To xiaors.RecordCount
'小类节点KEY为"XI"+rs("小类序号")
Set nodx = TreeView1.Nodes.Add("DA" + Trim(dars(0)), tvwChild, "XI" + Trim(xiaors(1)), Trim(xiaors(2)), 2, 1)
sql = "select * from jiedian where 大类序号=" & CInt(dars(0)) & " and 小类序号=" & xiaors(1) & ""
If Dianrs.State = adStateOpen Then Dianrs.Close
Dianrs.Open sql, cn, 1, 4
For j = 1 To Dianrs.RecordCount
Set nodx = TreeView1.Nodes.Add("XI" + Trim(CStr(xiaors(1))), tvwChild, "JD" & Trim(CStr(Dianrs(2))), Trim(Dianrs(3)), 3, 3)
Dianrs.MoveNext
Next j
xiaors.MoveNext
Next I
dars.MoveNext
Loop
你稍微修改一下就可以用了。这个也是三级的。
sql = "select * from da "
dars.Open sql, cn, adOpenKeyset, adLockBatchOptimistic
Do While Not dars.EOF
'大类节点KEY为"DA"+rs("大类序号")
Set nodx = TreeView1.Nodes.Add(, , "DA" + Trim(dars(0)), Trim(dars(1)), 2, 1)
sql = "select * from xiao where 大类序号=" & CInt(dars(0))
If xiaors.State = adStateOpen Then xiaors.Close
xiaors.Open sql, cn, adOpenKeyset, adLockBatchOptimistic
For I = 1 To xiaors.RecordCount
'小类节点KEY为"XI"+rs("小类序号")
Set nodx = TreeView1.Nodes.Add("DA" + Trim(dars(0)), tvwChild, "XI" + Trim(xiaors(1)), Trim(xiaors(2)), 2, 1)
sql = "select * from jiedian where 大类序号=" & CInt(dars(0)) & " and 小类序号=" & xiaors(1) & ""
If Dianrs.State = adStateOpen Then Dianrs.Close
Dianrs.Open sql, cn, 1, 4
For j = 1 To Dianrs.RecordCount
Set nodx = TreeView1.Nodes.Add("XI" + Trim(CStr(xiaors(1))), tvwChild, "JD" & Trim(CStr(Dianrs(2))), Trim(Dianrs(3)), 3, 3)
Dianrs.MoveNext
Next j
xiaors.MoveNext
Next I
dars.MoveNext
Loop
你稍微修改一下就可以用了。这个也是三级的。
#12
我发给你了。
#13
感谢lazygod,感谢大家!!!
#14
gooooooood
#1
可以!easy
建议一次只展开一级!
建议一次只展开一级!
#2
同上
#3
http://www.wzjcw.net/vbgood/taishan/index.html
【迷你数据库浏览器】源代码。
【迷你数据库浏览器】源代码。
#4
首先是建立一级目录,把字段guo中的记录分组,然后一个一个加上去,然后给每个
节点下加一个临时节点(由于国家节点现在是隐藏的,临时节点用户看不到)。当发生节点展开事件时,获得节点的标题,删除其下的临时节点,然后根据标题查询guo字段等于标题的记录,将记录按sheng字段分组,分别添加到展开的国家节点下面。shi节点的做法同上。
节点下加一个临时节点(由于国家节点现在是隐藏的,临时节点用户看不到)。当发生节点展开事件时,获得节点的标题,删除其下的临时节点,然后根据标题查询guo字段等于标题的记录,将记录按sheng字段分组,分别添加到展开的国家节点下面。shi节点的做法同上。
#5
Set Nodx = TreeView1.Nodes.Add(, , "firstchild", "国家名称")
Nodx.Image = 1
RsBook.Open "select distinct guo from 表", cn, adOpenForwardOnly, adLockReadOnly
If Not RsBook.BOF Then RsBook.MoveFirst
Do Until RsBook.EOF
Set Nodx = TreeView1.Nodes.Add("firstchild", tvwChild, "children" & r, RsBook.Fields("guo"))
Nodx.Image = 2
RsBanben.Open "select distinct sheng from 表 where guo='" & RsBook(0).Value & "'", cn, adOpenForwardOnly, adLockReadOnly
If RsBanben.EOF = False And RsBanben.BOF = False Then
Do Until RsBanben.EOF
Set Nodx = TreeView1.Nodes.Add("children" & r, tvwChild, "schildren" & j, RsBanben.Fields("sheng"))
Nodx.Image = 3
Rspic.Open "select distinct shi from 表 where guo='" & RsBook(0).Value & "'" & " and " & "sheng='" & RsBanben(0).Value & "'", cn, adOpenForwardOnly, adLockReadOnly
If Rspic.EOF = False And Rspic.BOF = False Then
Do Until Rspic.EOF
Set Nodx = TreeView1.Nodes.Add("schildren" & j, tvwChild, "Tchildren" & k, Rspic.Fields("shi"))
Nodx.Image = 4
k = k + 1
Rspic.MoveNext
Loop
End If
Rspic.Close
j = j + 1
RsBanben.MoveNext
Loop
End If
RsBanben.Close
r = r + 1
RsBook.MoveNext
Loop
RsBook.Close
这是我以前的例子经改动后,不知能看懂?
能看懂的话给小妹加点分
Nodx.Image = 1
RsBook.Open "select distinct guo from 表", cn, adOpenForwardOnly, adLockReadOnly
If Not RsBook.BOF Then RsBook.MoveFirst
Do Until RsBook.EOF
Set Nodx = TreeView1.Nodes.Add("firstchild", tvwChild, "children" & r, RsBook.Fields("guo"))
Nodx.Image = 2
RsBanben.Open "select distinct sheng from 表 where guo='" & RsBook(0).Value & "'", cn, adOpenForwardOnly, adLockReadOnly
If RsBanben.EOF = False And RsBanben.BOF = False Then
Do Until RsBanben.EOF
Set Nodx = TreeView1.Nodes.Add("children" & r, tvwChild, "schildren" & j, RsBanben.Fields("sheng"))
Nodx.Image = 3
Rspic.Open "select distinct shi from 表 where guo='" & RsBook(0).Value & "'" & " and " & "sheng='" & RsBanben(0).Value & "'", cn, adOpenForwardOnly, adLockReadOnly
If Rspic.EOF = False And Rspic.BOF = False Then
Do Until Rspic.EOF
Set Nodx = TreeView1.Nodes.Add("schildren" & j, tvwChild, "Tchildren" & k, Rspic.Fields("shi"))
Nodx.Image = 4
k = k + 1
Rspic.MoveNext
Loop
End If
Rspic.Close
j = j + 1
RsBanben.MoveNext
Loop
End If
RsBanben.Close
r = r + 1
RsBook.MoveNext
Loop
RsBook.Close
这是我以前的例子经改动后,不知能看懂?
能看懂的话给小妹加点分
#6
select guo from T Group by guo
select sheng from T where guo ='TreeView的某节点' Group by sheng
select shi from T where guo ='TreeView的某国节点' and sheng='guo ='TreeView的某省节点' Group by shi
select sheng from T where guo ='TreeView的某节点' Group by sheng
select shi from T where guo ='TreeView的某国节点' and sheng='guo ='TreeView的某省节点' Group by shi
#7
select guo from T Group by guo
select sheng from T where guo ='TreeView的某节点' Group by sheng
select shi from T where guo ='TreeView的某国节点' and sheng='TreeView的某省节点' Group by shi
select sheng from T where guo ='TreeView的某节点' Group by sheng
select shi from T where guo ='TreeView的某国节点' and sheng='TreeView的某省节点' Group by shi
#8
这里不好说,给我你的信箱,我给你发一个过去。
#9
程序如下:
Dim con As New ADODB.Connection
Dim recGuo As New ADODB.Recordset
Dim recSheng As New ADODB.Recordset
Dim recShi As New ADODB.Recordset
'打开库连接
con.Open .....
'先读取国信息
recGuo.Open "select distinct guo from table", con, adOpenStatic, adLockOptimistic
Do Until recGuo.EOF
'向TreeView中添加国名
TreeView.Nodes.Add , , recGuo.Fields("guo"), recGuo.Fields("guo"), 1
'读取此国下的省信息
recSheng.Open "select sheng from table where guo='" & recGuo.Fields("guo") & "'", con, adOpenStatic, adLockOptimistic
Do Until recSheng.EOF
'向TreeView中添加省名
TreeView.Nodes.Add recGuo.Fields("guo"), tvwChild, recSheng.Fields("sheng"), recSheng.Fields("sheng"), 2
'读取此省下的市信息
recShi.Open "select shi from table where guo='" & recGuo.Fields("guo") & "' and sheng='" & recSheng.Fields("sheng") & "'", con, adOpenStatic, adLockOptimistic
Do Until recShi.EOF
'向TreeView中添加市名
Set treNode = TreeView.Nodes.Add(recSheng.Fields("sheng"), tvwChild, recShi.Fields("shi"), recShi.Fields("shi"), 3)
recShi.MoveNext
Loop
recPufferTemp.MoveNext
Loop
Loop
recShi.Close
recSheng.Close
recGuo.Close
Set recShi = Nothing
Set recSheng = Nothing
Set recGuo = Nothing
Dim con As New ADODB.Connection
Dim recGuo As New ADODB.Recordset
Dim recSheng As New ADODB.Recordset
Dim recShi As New ADODB.Recordset
'打开库连接
con.Open .....
'先读取国信息
recGuo.Open "select distinct guo from table", con, adOpenStatic, adLockOptimistic
Do Until recGuo.EOF
'向TreeView中添加国名
TreeView.Nodes.Add , , recGuo.Fields("guo"), recGuo.Fields("guo"), 1
'读取此国下的省信息
recSheng.Open "select sheng from table where guo='" & recGuo.Fields("guo") & "'", con, adOpenStatic, adLockOptimistic
Do Until recSheng.EOF
'向TreeView中添加省名
TreeView.Nodes.Add recGuo.Fields("guo"), tvwChild, recSheng.Fields("sheng"), recSheng.Fields("sheng"), 2
'读取此省下的市信息
recShi.Open "select shi from table where guo='" & recGuo.Fields("guo") & "' and sheng='" & recSheng.Fields("sheng") & "'", con, adOpenStatic, adLockOptimistic
Do Until recShi.EOF
'向TreeView中添加市名
Set treNode = TreeView.Nodes.Add(recSheng.Fields("sheng"), tvwChild, recShi.Fields("shi"), recShi.Fields("shi"), 3)
recShi.MoveNext
Loop
recPufferTemp.MoveNext
Loop
Loop
recShi.Close
recSheng.Close
recGuo.Close
Set recShi = Nothing
Set recSheng = Nothing
Set recGuo = Nothing
#10
我的Email:songzj198@0451.com
#11
If dars.State = adStateOpen Then dars.Close
sql = "select * from da "
dars.Open sql, cn, adOpenKeyset, adLockBatchOptimistic
Do While Not dars.EOF
'大类节点KEY为"DA"+rs("大类序号")
Set nodx = TreeView1.Nodes.Add(, , "DA" + Trim(dars(0)), Trim(dars(1)), 2, 1)
sql = "select * from xiao where 大类序号=" & CInt(dars(0))
If xiaors.State = adStateOpen Then xiaors.Close
xiaors.Open sql, cn, adOpenKeyset, adLockBatchOptimistic
For I = 1 To xiaors.RecordCount
'小类节点KEY为"XI"+rs("小类序号")
Set nodx = TreeView1.Nodes.Add("DA" + Trim(dars(0)), tvwChild, "XI" + Trim(xiaors(1)), Trim(xiaors(2)), 2, 1)
sql = "select * from jiedian where 大类序号=" & CInt(dars(0)) & " and 小类序号=" & xiaors(1) & ""
If Dianrs.State = adStateOpen Then Dianrs.Close
Dianrs.Open sql, cn, 1, 4
For j = 1 To Dianrs.RecordCount
Set nodx = TreeView1.Nodes.Add("XI" + Trim(CStr(xiaors(1))), tvwChild, "JD" & Trim(CStr(Dianrs(2))), Trim(Dianrs(3)), 3, 3)
Dianrs.MoveNext
Next j
xiaors.MoveNext
Next I
dars.MoveNext
Loop
你稍微修改一下就可以用了。这个也是三级的。
sql = "select * from da "
dars.Open sql, cn, adOpenKeyset, adLockBatchOptimistic
Do While Not dars.EOF
'大类节点KEY为"DA"+rs("大类序号")
Set nodx = TreeView1.Nodes.Add(, , "DA" + Trim(dars(0)), Trim(dars(1)), 2, 1)
sql = "select * from xiao where 大类序号=" & CInt(dars(0))
If xiaors.State = adStateOpen Then xiaors.Close
xiaors.Open sql, cn, adOpenKeyset, adLockBatchOptimistic
For I = 1 To xiaors.RecordCount
'小类节点KEY为"XI"+rs("小类序号")
Set nodx = TreeView1.Nodes.Add("DA" + Trim(dars(0)), tvwChild, "XI" + Trim(xiaors(1)), Trim(xiaors(2)), 2, 1)
sql = "select * from jiedian where 大类序号=" & CInt(dars(0)) & " and 小类序号=" & xiaors(1) & ""
If Dianrs.State = adStateOpen Then Dianrs.Close
Dianrs.Open sql, cn, 1, 4
For j = 1 To Dianrs.RecordCount
Set nodx = TreeView1.Nodes.Add("XI" + Trim(CStr(xiaors(1))), tvwChild, "JD" & Trim(CStr(Dianrs(2))), Trim(Dianrs(3)), 3, 3)
Dianrs.MoveNext
Next j
xiaors.MoveNext
Next I
dars.MoveNext
Loop
你稍微修改一下就可以用了。这个也是三级的。
#12
我发给你了。
#13
感谢lazygod,感谢大家!!!
#14
gooooooood