============================================
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作者: tmtony 时间: 2008-4-13 11:08
在属性里设置作者: tanhong 时间: 2008-4-13 11:13
是我写快了,labeledit属性是可以修改的,但不是布尔值,而是两个常量,
0—tvwAutomatic 为默认表示允许修改节点
1—tvwManual 表示不可修改节点
LabelEdit 属性
用来指定或返回 TreeView 控件节点是否可以由用户来修改。
语法
object.LabelEdit [ = value ]作者: t小宝 时间: 2008-4-13 11:15 标题: 第二个问题 Private Sub CmdExpend_Click() '这句用于树的展开收缩按扭
On Error GoTo Err_CmdExpend_Click
Dim i As Integer
blnEx = Not blnEx
Me.tv.SetFocus
If blnEx Then
For i = 1 To tv.Nodes.Count
tv.Nodes(i).Expanded = True '展开所有节点
Next i
Me.CmdExpend.Caption = "收起-针车工人目录"
Me.tv.Nodes(tv.Nodes.Count).Selected = True
Else
For i = 1 To tv.Nodes.Count
tv.Nodes(i).Expanded = False '收起所有节点
Next i
Me.CmdExpend.Caption = "展开-针车工人目录"
End If