|
4#
楼主 |
发表于 2008-4-13 10:37:54
|
只看该作者
两个问题:
1、想实现树不可直接编辑。
2、点击“CmdExpend”按扭,问题是,它会滚到最下面,,我不想让树滚到最下面。
展开树时,,树里的记录焦点在最上面。。
============================================
Option Compare Database
Option Explicit
Dim blnEx As Boolean '这句用于树的展开收缩
===================================
Private Sub CmdExpend_Click() '这句用于树的展开收缩按扭
On Error GoTo Err_CmdExpend_Click
Dim i As Integer
blnEx = Not blnEx
If blnEx Then
For i = 1 To tv.Nodes.Count
tv.Nodes(i).Expanded = True '展开所有节点
Next i
Me.CmdExpend.Caption = "收起-针车工人目录"
Else
For i = 1 To tv.Nodes.Count
tv.Nodes(i).Expanded = False '收起所有节点
Next i
Me.CmdExpend.Caption = "展开-针车工人目录"
End If
Exit_CmdExpend_Click:
Exit Sub
Err_CmdExpend_Click:
MsgBox Err.Description
Resume Exit_CmdExpend_Click
End Sub
========================================================
Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim rcd As New ADODB.Recordset
Dim k As Integer, i As Integer
Set cn = CurrentProject.Connection
Dim TempNode As Node
On Error GoTo Err:
' Set TempNode = Me.tv.Nodes.Add(, , "a", "鞋厂车位员工列表", 1, 3)
If Nz(DLookup("[工人编号]", "工人"), 0) <> 0 Then
rcd.Open "SELECT left(工人编号,2) as a FROM 工人 group by left(工人编号,2) ORDER BY left(工人编号,2) Asc", cn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
rcd.MoveFirst
While Not rcd.EOF
Set TempNode = tv.Nodes.Add(, , rcd![a], rcd![a], 3, 2)
rcd.MoveNext
Wend
rcd.Close
rcd.Open "SELECT left(工人编号,2) as a,工人编号,工人姓名 FROM 工人 group by left(工人编号,2),工人编号,工人姓名 ORDER BY left(工人编号,2) Asc", cn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
rcd.MoveFirst
While Not rcd.EOF
Set TempNode = tv.Nodes.Add(CStr(rcd(0)), tvwChild, rcd![工人编号], rcd![工人编号] & ":" & rcd![工人姓名], 3, 2)
rcd.MoveNext
Wend
rcd.Close
End If
Err:
Debug.Print Err.Number, Err.Description
Exit Sub
End Sub |
|