excel vba里treeview控件,节点被排序了,求修改
DimCNNAsNewADODB.ConnectionDimRSAsNewADODB.Recordset,RS1AsNewADODB.Recordset,RS2AsNew...
Dim CNN As New ADODB.Connection
Dim RS As New ADODB.Recordset, RS1 As New ADODB.Recordset, RS2 As New ADODB.Recordset
Dim pthStr As String
Dim SQL As String
Dim i As Integer
Private Sub CommandButton4_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False '关闭屏幕更新可加快宏的执行速度
Application.DisplayAlerts = False
On Error Resume Next
TreeView1.Nodes.Clear
pthStr = ThisWorkbook.Path & "\数据库.mdb"
CNN.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & pthStr
SQL = "select distinct 材料大类 From 材料品名 "
RS.Open SQL, CNN, adOpenKeyset, adLockOptimistic
i1 = 1
Do While Not RS.EOF
DaLei = RS.Fields("材料大类")
TreeView1.Nodes.Add , , "No" & i1, DaLei
SQL = "select distinct 材料小类 From 材料品名 where 材料大类='" & DaLei & "'"
RS1.Open SQL, CNN, adOpenKeyset, adLockOptimistic
i2 = 1
Do While Not RS1.EOF
XiaoLei = RS1.Fields("材料小类")
TreeView1.Nodes.Add "No" & i1, tvwChild, "No" & i1 & i2, XiaoLei
SQL = "select 材料规格及名称 From 材料品名 where 材料大类='" & DaLei & "' and 材料小类='" & XiaoLei & "'"
RS2.Open SQL, CNN, adOpenKeyset, adLockOptimistic
Do While Not RS2.EOF
banjibh = RS2.Fields("材料规格及名称")
TreeView1.Nodes.Add "No" & i1 & i2, tvwChild, banjibh, banjibh
RS2.MoveNext
Loop
RS2.Close
RS1.MoveNext
i2 = i2 + 1
Loop
RS1.Close
RS.MoveNext
i1 = i1 + 1
Loop
RS.Close
Set RS = Nothing: Set RS1 = Nothing: Set RS2 = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
以上代码是引用access数据,一级节点为材料大类那一列,存储时已经有顺序的,但按以上代码做出来的treeview显示为重新排序后的,我不想按文字首字母排序,谁能帮忙修改下,谢谢
有没有会的???????????? 展开
Dim RS As New ADODB.Recordset, RS1 As New ADODB.Recordset, RS2 As New ADODB.Recordset
Dim pthStr As String
Dim SQL As String
Dim i As Integer
Private Sub CommandButton4_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False '关闭屏幕更新可加快宏的执行速度
Application.DisplayAlerts = False
On Error Resume Next
TreeView1.Nodes.Clear
pthStr = ThisWorkbook.Path & "\数据库.mdb"
CNN.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & pthStr
SQL = "select distinct 材料大类 From 材料品名 "
RS.Open SQL, CNN, adOpenKeyset, adLockOptimistic
i1 = 1
Do While Not RS.EOF
DaLei = RS.Fields("材料大类")
TreeView1.Nodes.Add , , "No" & i1, DaLei
SQL = "select distinct 材料小类 From 材料品名 where 材料大类='" & DaLei & "'"
RS1.Open SQL, CNN, adOpenKeyset, adLockOptimistic
i2 = 1
Do While Not RS1.EOF
XiaoLei = RS1.Fields("材料小类")
TreeView1.Nodes.Add "No" & i1, tvwChild, "No" & i1 & i2, XiaoLei
SQL = "select 材料规格及名称 From 材料品名 where 材料大类='" & DaLei & "' and 材料小类='" & XiaoLei & "'"
RS2.Open SQL, CNN, adOpenKeyset, adLockOptimistic
Do While Not RS2.EOF
banjibh = RS2.Fields("材料规格及名称")
TreeView1.Nodes.Add "No" & i1 & i2, tvwChild, banjibh, banjibh
RS2.MoveNext
Loop
RS2.Close
RS1.MoveNext
i2 = i2 + 1
Loop
RS1.Close
RS.MoveNext
i1 = i1 + 1
Loop
RS.Close
Set RS = Nothing: Set RS1 = Nothing: Set RS2 = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
以上代码是引用access数据,一级节点为材料大类那一列,存储时已经有顺序的,但按以上代码做出来的treeview显示为重新排序后的,我不想按文字首字母排序,谁能帮忙修改下,谢谢
有没有会的???????????? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询