VB集合中的关键字不唯一是什么原因呢
PublicSubTree_change()DimKey,Text,BHAsStringDimNodAsNodeKey="设备分类"Text="设备分类"SetNode1...
Public Sub Tree_change()
Dim Key, Text, BH As String
Dim Nod As Node
Key = "设备分类"
Text = "设备分类"
Set Node1 = TreeView1.Nodes.Add(, , Key, Text, 1)
Adodc1.RecordSource = "select * from tb_lbgl "
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
Do While Adodc1.Recordset.EOF = False
Key = Trim(Adodc1.Recordset.Fields("类别名称"))
Text = Adodc1.Recordset.Fields("类别名称")
Set node2 = TreeView1.Nodes.Add(Node1.Index, tvwChild, Key, Text, 1)
Adodc2.RecordSource = "select * from View_sbfl where 类别名称='" + Adodc1.Recordset.Fields("类别名称") + "'"
Adodc2.Refresh
If Adodc2.Recordset.RecordCount > 0 Then
Adodc2.Recordset.MoveFirst
Do While Adodc2.Recordset.EOF = False
Key = Trim(Adodc2.Recordset.Fields("设备名称"))
Text = Adodc2.Recordset.Fields("设备名称")
Set Node3 = TreeView1.Nodes.Add(node2.Index, tvwChild, Key, Text, 1)
Adodc2.Recordset.MoveNext
Loop
End If
Adodc1.Recordset.MoveNext
Loop
End If
End Sub 展开
Dim Key, Text, BH As String
Dim Nod As Node
Key = "设备分类"
Text = "设备分类"
Set Node1 = TreeView1.Nodes.Add(, , Key, Text, 1)
Adodc1.RecordSource = "select * from tb_lbgl "
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
Do While Adodc1.Recordset.EOF = False
Key = Trim(Adodc1.Recordset.Fields("类别名称"))
Text = Adodc1.Recordset.Fields("类别名称")
Set node2 = TreeView1.Nodes.Add(Node1.Index, tvwChild, Key, Text, 1)
Adodc2.RecordSource = "select * from View_sbfl where 类别名称='" + Adodc1.Recordset.Fields("类别名称") + "'"
Adodc2.Refresh
If Adodc2.Recordset.RecordCount > 0 Then
Adodc2.Recordset.MoveFirst
Do While Adodc2.Recordset.EOF = False
Key = Trim(Adodc2.Recordset.Fields("设备名称"))
Text = Adodc2.Recordset.Fields("设备名称")
Set Node3 = TreeView1.Nodes.Add(node2.Index, tvwChild, Key, Text, 1)
Adodc2.Recordset.MoveNext
Loop
End If
Adodc1.Recordset.MoveNext
Loop
End If
End Sub 展开
2个回答
展开全部
典型的编码有重复数据, Key 是不能重复的值,也是判断选中时使用的。
因此如果重复不能排除,请加一个for循环一个N逐条插入。Key.
我给你两个例子:
Dim ls_sql As String
Rs_OpenQ LS_Rs_ks, "SELECT 编码 as 科室编码,科别名称 FROM dict_kbb where 住院标志 = '是'" '科室信息
ls_sql = " select 序号 ,科别编码,科别名称,病房,是否加床,床位号,床位名称,床位编码,床位费,诊疗名称,诊疗编码,诊疗费,取暖名称,取暖编码,取暖费,降温名称,降温编码,降温费,描述 " _
& " From zyc_dict_cwb " _
& " where 是否有效 = '是'" _
& " order by 病房,床位号 "
Rs_OpenQ LS_Rs_cw, ls_sql '床位信息,为以后筛选准备
'加载科室信息到treeview
If LS_Rs_ks.EOF And LS_Rs_ks.BOF Then
Exit Sub
End If
TV_KS.Nodes.Clear
TV_KS.Nodes.Add , , "zy_ks", "住院科别", 1, 2
LS_Rs_ks.MoveFirst
Do While Not LS_Rs_ks.EOF
If Trim(LS_Rs_ks!科别名称) <> "" Then
TV_KS.Nodes.Add "zy_ks", tvwChild, "zy_" + Trim(LS_Rs_ks!科室编码), Trim(LS_Rs_ks!科别名称), 3, 4
End If
LS_Rs_ks.MoveNext
Loop
TV_KS.Nodes(1).Expanded = True
TV_KS.Tag = "zy_ks"
TV_KS.Nodes(1).Selected = True
实例2:
Public Sub Load_data()
'数据加载
Dim I As Long
Dim J As Integer
Dim iindex As Long
Dim rsWH As New ADODB.Recordset
'加载第一层菜单
Tv.Nodes.Clear
rsWH.CursorLocation = adUseClient
rsWH.Open "select distinct 科别 from dict_czyb order by 科别 ", dbMainConnect, adOpenStatic, adLockReadOnly
If rsWH.EOF And rsWH.BOF Then Exit Sub
Do Until rsWH.EOF
With Tv
.Nodes.Add , , Trim(rsWH![科别]) + "n", rsWH![科别], 1, 2
J = J + 1
rsWH.MoveNext
End With
Loop
'加载第二层菜单
For I = 1 To J
If rsWH.State = adStateOpen Then rsWH.Close
rsWH.CursorLocation = adUseClient
rsWH.Open "select distinct 编码,姓名 from dict_czyb where 科别 = '" + Left(Tv.Nodes(I).Key, Len(Tv.Nodes(I).Key) - 1) + "'", dbMainConnect, adOpenStatic, adLockReadOnly
Do While Not rsWH.EOF
If Trim(rsWH!姓名 & "") <> "" Then
Tv.Nodes.Add I, tvwChild, , Trim(rsWH!姓名), 3, 4
End If
rsWH.MoveNext
Loop
Next I
rsWH.Close
Set rsWH = Nothing
End Sub
因此如果重复不能排除,请加一个for循环一个N逐条插入。Key.
我给你两个例子:
Dim ls_sql As String
Rs_OpenQ LS_Rs_ks, "SELECT 编码 as 科室编码,科别名称 FROM dict_kbb where 住院标志 = '是'" '科室信息
ls_sql = " select 序号 ,科别编码,科别名称,病房,是否加床,床位号,床位名称,床位编码,床位费,诊疗名称,诊疗编码,诊疗费,取暖名称,取暖编码,取暖费,降温名称,降温编码,降温费,描述 " _
& " From zyc_dict_cwb " _
& " where 是否有效 = '是'" _
& " order by 病房,床位号 "
Rs_OpenQ LS_Rs_cw, ls_sql '床位信息,为以后筛选准备
'加载科室信息到treeview
If LS_Rs_ks.EOF And LS_Rs_ks.BOF Then
Exit Sub
End If
TV_KS.Nodes.Clear
TV_KS.Nodes.Add , , "zy_ks", "住院科别", 1, 2
LS_Rs_ks.MoveFirst
Do While Not LS_Rs_ks.EOF
If Trim(LS_Rs_ks!科别名称) <> "" Then
TV_KS.Nodes.Add "zy_ks", tvwChild, "zy_" + Trim(LS_Rs_ks!科室编码), Trim(LS_Rs_ks!科别名称), 3, 4
End If
LS_Rs_ks.MoveNext
Loop
TV_KS.Nodes(1).Expanded = True
TV_KS.Tag = "zy_ks"
TV_KS.Nodes(1).Selected = True
实例2:
Public Sub Load_data()
'数据加载
Dim I As Long
Dim J As Integer
Dim iindex As Long
Dim rsWH As New ADODB.Recordset
'加载第一层菜单
Tv.Nodes.Clear
rsWH.CursorLocation = adUseClient
rsWH.Open "select distinct 科别 from dict_czyb order by 科别 ", dbMainConnect, adOpenStatic, adLockReadOnly
If rsWH.EOF And rsWH.BOF Then Exit Sub
Do Until rsWH.EOF
With Tv
.Nodes.Add , , Trim(rsWH![科别]) + "n", rsWH![科别], 1, 2
J = J + 1
rsWH.MoveNext
End With
Loop
'加载第二层菜单
For I = 1 To J
If rsWH.State = adStateOpen Then rsWH.Close
rsWH.CursorLocation = adUseClient
rsWH.Open "select distinct 编码,姓名 from dict_czyb where 科别 = '" + Left(Tv.Nodes(I).Key, Len(Tv.Nodes(I).Key) - 1) + "'", dbMainConnect, adOpenStatic, adLockReadOnly
Do While Not rsWH.EOF
If Trim(rsWH!姓名 & "") <> "" Then
Tv.Nodes.Add I, tvwChild, , Trim(rsWH!姓名), 3, 4
End If
rsWH.MoveNext
Loop
Next I
rsWH.Close
Set rsWH = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询