|
本帖最后由 鱼儿游游 于 2012-7-1 10:26 编辑
咱家是猫 发表于 2012-6-30 11:07 ![]()
用了一个最方便,但不严谨的做法.这种做法要求你的所有节点的Text都不能有相同的.
Private Sub xTree_Nod ...
下面的方法完美解决了:要求你的所有节点的Text都不能有相同的。
- '=================================================================
- '功能:只展开树当前节点,其它节点不展开
- '
- '调用: GetTreeAllParentNode_Key
- '
- '作者:鱼儿游游 QQ:7178000
- '
- '时间:2012-06-30
- '=================================================================
- Private Sub xTree_NodeClick(ByVal Node As Object)
- On Error GoTo Err_Handler
- Dim tvwTree As Object
- Dim dicNodeKey As Object
- Dim strNodeKey As String
- Dim intI As Integer
- Set tvwTree = Me.xTree.Object
- With tvwTree
- If GetTreeAllParentNode_Key(Node, dicNodeKey) Then
- For intI = 1 To .Nodes.Count
- strNodeKey = .Nodes(intI).Key
- If Not dicNodeKey.Exists(strNodeKey) Then .Nodes(intI).Expanded = False
- Next
- End If
- .Nodes(Node.Index).Selected = True
- End With
- Exit_Handler:
- Set tvwTree = Nothing
- Set dicNodeKey = Nothing
- Exit Sub
- Err_Handler:
- Resume Exit_Handler
- End Sub
- '=================================================================
- '-函数名称: GetTreeAllParentNode_Key
- '-功能描述: 返回指定树节点的所有父节点的KEY
- '-输入参数: NodeX ......... 树中的任一节点
- ' dicNodeKey .... 返回值
- '-返回参数: 1、dicNodeKey 的内容,就是指定树节点的所有父节点的KEY
- ' 2、程序不出错返回:True,否则返回:False
- '-作 者: 鱼儿游游 QQ:7178000
- '-创建日期; 2012-06-30
- '=================================================================
- Private Function GetTreeAllParentNode_Key(ByVal NodeX As Node, ByRef dicNodeKey As Object) As Boolean
- On Error GoTo Err_Handler
- Dim blnResult As Boolean
- Dim nodCurrent As Node
- blnResult = False
- Set nodCurrent = NodeX
- Set dicNodeKey = CreateObject("Scripting.Dictionary")
- If Not dicNodeKey Is Nothing Then dicNodeKey.RemoveAll
- Do Until nodCurrent.Parent Is Nothing
- Set nodCurrent = nodCurrent.Parent
- dicNodeKey(nodCurrent.Key) = ""
- Loop
- blnResult = True
- Exit_Handler:
- GetTreeAllParentNode_Key = blnResult
- Set nodCurrent = Nothing
- Exit Function
- Err_Handler:
- blnResult = False
- MsgBox Err.Description, vbCritical, "返回选择节点的所有父点的KEY的集合函数"
- Resume Exit_Handler
- End Function
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|