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显示为重新排序后的,我不想按文字首字母排序,谁能帮忙修改下,谢谢
有没有会的????????????
excel vba里treeview控件,节点被排序了,求修改
答案:2 悬赏:30 手机版
解决时间 2021-02-16 02:26
- 提问者网友:感性作祟
- 2021-02-15 15:26
最佳答案
- 五星知识达人网友:撞了怀
- 2021-02-15 15:46
treeview控件有一个sort(排序)属性,修改为fales就行了
全部回答
- 1楼网友:怀裏藏嬌
- 2021-02-15 16:56
可以用如下代码实现: sub main for i=20 to 89 step 3 for j=4 to 10 cells(i,j).interior.colorindex = xlautomatic next j next i end sub 关于此例中用到的interior对象: 对象代表指定对象的内部,为只读属性
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯