设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
楼主: fnsmydyang
打印 上一主题 下一主题

[ActiveX] 请教一个树节点展开问题。

[复制链接]
21#
 楼主| 发表于 2012-6-30 10:42:18 | 只看该作者
咱家是猫 发表于 2012-6-30 10:38
是噢,这个又忽略了,唉...这要考虑的东西还真多

嘻...,辛苦版主了。
22#
发表于 2012-6-30 11:07:13 | 只看该作者
用了一个最方便,但不严谨的做法.这种做法要求你的所有节点的Text都不能有相同的.

Private Sub xTree_NodeClick(ByVal Node As Object)

    On Error Resume Next
   
    Dim tree0 As TreeView
    Dim strPath As String
   
    Static intLastNode As Integer
   
    Set tree0 = Me.xTree.Object

    strPath = "\" & Node.FullPath & "\"
    If intLastNode <> 0 Then
        For i = 1 To tree0.Nodes.Count
            If tree0.Nodes(i).Expanded = True Then
                If InStr(strPath, "\" & tree0.Nodes(i).Text & "\") = 0 Then
                    tree0.Nodes(i).Expanded = False
                End If
            End If
        Next i
    End If
   
    intLastNode = Node.Index
    Node.Seleted = True
    Node.Expanded = True
   
    lngKM = Nz(Right(Node.Key, Len(Node.Key) - 1))
   
End Sub
23#
发表于 2012-6-30 11:08:39 | 只看该作者
本帖最后由 咱家是猫 于 2012-6-30 11:08 编辑

这个方法还是回到了老路上--循环,但此循环在执行时,进行了更多的比对,解决了闪的问题.
24#
 楼主| 发表于 2012-6-30 14:23:54 | 只看该作者
咱家是猫 发表于 2012-6-30 11:08
这个方法还是回到了老路上--循环,但此循环在执行时,进行了更多的比对,解决了闪的问题.

版主,我是用数组存储Indext 值,但是闪的问题不能解决,请帮忙,谢谢!!!
Private Sub xTree_NodeClick(ByVal Node As Object)
On Error Resume Next
    Dim NodeP As Node
    Dim N As Integer
    Dim I As Integer
    Dim IntParentIndext() As Integer
    Set NodeP = Node
    For N = 0 To 100
        If Not (NodeP.Parent Is Nothing) Then
            Set NodeP = NodeP.Parent
            'MsgBox NodeP.Index
            IntParentIndext(N) = NodeP.Index
        Else
            Exit For
        End If
    Next
    For I = 0 To UBound(IntParentIndext())
        For J = 1 To Me.xTree.Nodes.Count
            If IntParentIndext(I) <> Me.xTree.Nodes(J).indext Then
               Me.xTree.Nodes(J).Expanded = False
            Else
            End If
        Next J
    Next I
    Me.xTree.Nodes(Node.Index).Selected = True
End Sub
25#
发表于 2012-6-30 21:10:36 | 只看该作者
22楼的方法不行吗?
26#
 楼主| 发表于 2012-6-30 22:05:50 | 只看该作者
咱家是猫 发表于 2012-6-30 21:10
22楼的方法不行吗?

行的通,谢谢,只是想用不同的方法试一下。

点击这里给我发消息

27#
发表于 2012-7-1 09:49:49 | 只看该作者
本帖最后由 鱼儿游游 于 2012-7-1 10:26 编辑
咱家是猫 发表于 2012-6-30 11:07
用了一个最方便,但不严谨的做法.这种做法要求你的所有节点的Text都不能有相同的.

Private Sub xTree_Nod ...


下面的方法完美解决了:要求你的所有节点的Text都不能有相同的。

  1. '=================================================================
  2. '功能:只展开树当前节点,其它节点不展开
  3. '
  4. '调用: GetTreeAllParentNode_Key
  5. '
  6. '作者:鱼儿游游  QQ:7178000
  7. '
  8. '时间:2012-06-30
  9. '=================================================================
  10. Private Sub xTree_NodeClick(ByVal Node As Object)
  11. On Error GoTo Err_Handler
  12.     Dim tvwTree    As Object
  13.     Dim dicNodeKey As Object
  14.     Dim strNodeKey As String
  15.     Dim intI As Integer
  16.     Set tvwTree = Me.xTree.Object
  17.     With tvwTree
  18.         If GetTreeAllParentNode_Key(Node, dicNodeKey) Then
  19.             For intI = 1 To .Nodes.Count
  20.                strNodeKey = .Nodes(intI).Key
  21.                If Not dicNodeKey.Exists(strNodeKey) Then .Nodes(intI).Expanded = False
  22.             Next
  23.         End If
  24.         .Nodes(Node.Index).Selected = True
  25.     End With
  26. Exit_Handler:
  27.     Set tvwTree = Nothing
  28.     Set dicNodeKey = Nothing
  29.     Exit Sub
  30. Err_Handler:
  31.     Resume Exit_Handler
  32. End Sub

  33. '=================================================================
  34. '-函数名称: GetTreeAllParentNode_Key
  35. '-功能描述: 返回指定树节点的所有父节点的KEY
  36. '-输入参数: NodeX ......... 树中的任一节点
  37. '           dicNodeKey .... 返回值
  38. '-返回参数: 1、dicNodeKey 的内容,就是指定树节点的所有父节点的KEY
  39. '           2、程序不出错返回:True,否则返回:False
  40. '-作    者: 鱼儿游游  QQ:7178000
  41. '-创建日期; 2012-06-30
  42. '=================================================================
  43. Private Function GetTreeAllParentNode_Key(ByVal NodeX As Node, ByRef dicNodeKey As Object) As Boolean
  44. On Error GoTo Err_Handler
  45.     Dim blnResult  As Boolean
  46.     Dim nodCurrent As Node
  47.     blnResult = False
  48.     Set nodCurrent = NodeX
  49.     Set dicNodeKey = CreateObject("Scripting.Dictionary")
  50.     If Not dicNodeKey Is Nothing Then dicNodeKey.RemoveAll
  51.     Do Until nodCurrent.Parent Is Nothing
  52.        Set nodCurrent = nodCurrent.Parent
  53.        dicNodeKey(nodCurrent.Key) = ""
  54.     Loop
  55.     blnResult = True
  56. Exit_Handler:
  57.     GetTreeAllParentNode_Key = blnResult
  58.     Set nodCurrent = Nothing
  59.     Exit Function
  60. Err_Handler:
  61.     blnResult = False
  62.     MsgBox Err.Description, vbCritical, "返回选择节点的所有父点的KEY的集合函数"
  63.     Resume Exit_Handler
  64. End Function
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

点击这里给我发消息

28#
发表于 2012-7-3 10:59:00 | 只看该作者
树控件不是有个 单项选择(SingleSel) 的属性吗?选上它好象就行了吧?
29#
 楼主| 发表于 2012-7-3 16:01:54 | 只看该作者
鱼儿游游 发表于 2012-7-1 09:49
下面的方法完美解决了:要求你的所有节点的Text都不能有相同的。

几天没上论坛,有这么多的人帮我解决问题,非常感谢,真是学海无涯,山外有山了。
30#
 楼主| 发表于 2012-7-3 16:02:31 | 只看该作者
轻风 发表于 2012-7-3 10:59
树控件不是有个 单项选择(SingleSel) 的属性吗?选上它好象就行了吧?

谢谢了,我试试。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-10 08:20 , Processed in 0.095641 second(s), 32 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表