設(shè)為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

返回列表 發(fā)新帖
查看: 2736|回復(fù): 2
打印 上一主題 下一主題

[模塊/函數(shù)] TREEVIEW查找的問題

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2010-5-6 11:57:25 | 只看該作者 回帖獎勵 |倒序?yàn)g覽 |閱讀模式
本帖最后由 loginwjd303 于 2010-5-6 17:14 編輯

應(yīng)用論壇上一老師的TREEVIEW查找代碼到自己的TREE上但就是不行。請老師幫忙。
不會展開,單一節(jié)點(diǎn)就選不到如圖所示

本帖子中包含更多資源

您需要 登錄 才可以下載或查看,沒有帳號?注冊

x
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 分享淘帖 訂閱訂閱
2#
 樓主| 發(fā)表于 2010-5-10 16:20:52 | 只看該作者
Private Sub Form_Load()

    Dim Conn As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim strCARGOTYPE_NO As String
    Dim MaxLevel As Integer
    Dim i As Integer


    Set Conn = CurrentProject.Connection

    Me.TreeView0.Nodes.Add , , "NO.1", "物料分類"




        
        Set rst = Conn.Execute("SELECT CARGOTYPE_LEVEL,CARGOTYPE_NO,CARGOTYPE_BM,CARGOTYPE_NAME FROM Ylfl Order By CARGOTYPE_NO")
        
        Do Until rst.EOF

            If rst!CARGOTYPE_LEVEL = 1 Then   '頂層菜單
                Me.TreeView0.Nodes.Add "NO.1", tvwChild, "NO." & Trim(rst!CARGOTYPE_NO), Trim(rst!CARGOTYPE_BM)
               
               
               
               
               
            Else
               
       Me.TreeView0.Nodes.Add "NO." & Left(rst!CARGOTYPE_NO, (rst!CARGOTYPE_LEVEL - 1) * 4), tvwChild, "NO." & Trim(rst!CARGOTYPE_NO), Trim(rst!CARGOTYPE_BM)
               
            End If
            rst.MoveNext
        Loop
On Error Resume Next
    Application.CommandBars("menuTreeView").Delete
    Dim iBar As CommandBar
    Dim iButton As CommandBarButton
    Dim iCombo As CommandBarComboBox
    Set iBar = Application.CommandBars.Add(Name:=("menuTreeView"), Position:=msoBarPopup, Temporary:=True)
    With iBar
        Set iButton = .Controls.Add(Type:=msoControlButton)
        iButton.Caption = "增加  選定節(jié)點(diǎn)子節(jié)點(diǎn)(&A)"
        iButton.OnAction = "Get_rmTreeView_PopupSelection"
        iButton.Tag = "Add"
        iButton.FaceId = 240
        
        Set iButton = .Controls.Add(Type:=msoControlButton)
        iButton.Caption = "刪除  選定節(jié)點(diǎn)(&D)"
        iButton.OnAction = "Get_rmTreeView_PopupSelection"
        iButton.Tag = "Del"
        iButton.FaceId = 1088
        'delCARGOTYPE
        Set iButton = .Controls.Add(Type:=msoControlButton)
        iButton.Caption = "更改  選定節(jié)點(diǎn)文字(&M)"
        iButton.OnAction = "Get_rmTreeView_PopupSelection"
        iButton.Tag = "Mod"
        iButton.FaceId = 290
        Set iButton = .Controls.Add(Type:=msoControlButton)
        iButton.Caption = "查找下一個(gè)(&N)"
        iButton.OnAction = "Get_rmTreeView_PopupSelection"
        iButton.Tag = "NEXT"
        iButton.FaceId = 280
       ' .Controls.Add Type:=msoControlComboBox
      
        
        Set iCombo = .Controls.Add(Type:=msoControlComboBox)
        iCombo.Caption = "查找  選定節(jié)點(diǎn)下的文字(&F)"
        iCombo.OnAction = "Get_rmTreeView_PopupSelection"
        iCombo.Tag = "FIND"
        iCombo.DropDownLines = 8
        iCombo.DropDownWidth = 100
        iCombo.ListIndex = 0
        iCombo.BeginGroup = True
        End With
Me.TreeView0.LabelEdit = tvwManual
    Me.TreeView0.Visible = True
    Me.TreeView0.Nodes(1).Sorted = True
    Me.TreeView0.Nodes(1).Sorted = False

    Me.TreeView0.Nodes(1).Expanded = True
    'Me.TreeView0.EnsureVisible
End Sub



Private Sub TreeView0_NodeClick(ByVal node As Object)

    Dim strCARGOTYPE_NO As String
  Dim strSQL As String
   Dim i As Integer
   Dim n As Integer
   Dim strTip As String

    strCARGOTYPE_NO = Right(node.Key, Len(node.Key) - 3)
    '判斷是否是頂層
    If strCARGOTYPE_NO = "1" Then  '預(yù)先定義好的:NO.1,第3位向后的字符,所以是1
     strSQL = "SELECT * FROM Ylxx;"
  '  Dim i As Long
    Me![Text01] = node.Index
     
     
       Me.lblTip.Caption = "物料分類"
        Else
        'i = Len(strCARGOTYPE_NO)
        strSQL = "SELECT * FROM Ylxx WHERE left([CARGO_TYPE]," & i & ")='" & strCARGOTYPE_NO & "';"
           Dim strCode() As String
    Dim NodeID2 As String
    strCode = Split(node.Key, ".")
    NodeID2 = strCode(UBound(strCode))
   
   
     Me![Text01] = node.Index
        'Debug.Print I
        For n = 1 To i / perSectionLong
            strTip = strTip & Trim(CurrentDb.OpenRecordset("SELECT CARGOTYPE_BM FROM Ylfl where left([CARGOTYPE_NO]," _
                                                         & (n * perSectionLong) & ")='" & Left(strCARGOTYPE_NO, (n * perSectionLong)) & "' and CARGOTYPE_LEVEL=" & n & ";")(0).Value) & ">>"
        Next
       ' strTip = "物料分類" & ">>" & Left(strTip, Len(strTip) - 2)
        Me.lblTip.Caption = strTip
End If
    'Debug.Print strSQL
Me.Yl.Form.RecordSource = strSQL
  'Me.產(chǎn)品1.Form.RecordSource = strSQL
Me.Form.FilterOn = True
Me.Form.Filter = strSQL

End Sub
Private Sub treeview0_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
    Dim mNode As node
    Dim NodeID As String
    Dim strCode() As String
    Dim strSQL As String
    Dim rst As DAO.Recordset
    Set mNode = TreeView0.SelectedItem
    Dim i As Integer
    strCode = Split(mNode.Key, "_")
    NodeID = strCode(UBound(strCode))
    'If blNodeClick Then
        If Button = 2 Then             ' 鼠標(biāo)右鍵 點(diǎn)擊 TreeView的Node
            iSQLs = ""                 '公用變量
            Dim combo As CommandBarControl
            Set combo = CommandBars("menuTreeView").FindControl(Tag:="FIND")
'            combo.Text = ""
            Application.CommandBars("menuTreeView").ShowPopup
            Select Case UCase(iSQLs)        '公用變量 iSQLs 的值由CommandBars("menuTreeView").ShowPopup的指定宏返回
            Case "ADD"
            Call addCARGOTYPE
            Case "del"
            Call delCARGOTYPE
            Case "NEXT"
             Call popFIND(mNode, Trim(combo.Text), False)
            ''Case findA
           
              Case "FIND"
                    If Trim(combo.Text) <> "" Then
                      Me.Painting = False
                        DoCmd.Hourglass True
                      Call popFIND(mNode, Trim(combo.Text), False)
                       With combo
                            Dim listFound As Boolean
                            If .ListCount > 0 Then
                               For i = 1 To .ListCount
                                   If .List(i) = .Text Then
                                        listFound = True
                                   End If
                               Next
                          End If
                           If listFound = False Then .AddItem .Text
                        End With
                        Me.Painting = True
                        DoCmd.Hourglass False
                    End If
                    End Select
                    End If
                   End Sub
Function popFIND(NodeX As node, findText As String, blnFound As Boolean)
If blnFound = True Then Exit Function
Dim i As Integer
On Error Resume Next
' tj = Nz(Me.Text27, 0)
'If Nz(Me.Text27, 0) = 0 Then Exit Sub
For i = Inti + 1 To Me.TreeView0.Nodes.Count
    If Me.TreeView0.Nodes(i).Text Like "*" & Trim(findText) & "*" Then
        Me.TreeView0.Nodes(i).Selected = True
        Me.TreeView0.SetFocus
        TreeView0_NodeClick Me.TreeView0.SelectedItem
        Inti = i
        Exit Function
    End If
    Inti = i
Next
If Inti = Me.TreeView0.Nodes.Count Then
Inti = 1
MsgBox "沒有了"
Exit Function
End If
'If NodeX.Children = 0 Then Exit Function

  ' Dim i As Long
  ' strCode = Split(NodeX.Key, ".")
  ' NodeID = strCode(UBound(strCode))
  ' Dim childNode As node
   'If InStr(1, NodeX.Text, findText, vbTextCompare) > 0 Then
           'NodeX.Selected = True
           'If NodeX.Index > 1 Then NodeX.Parent.Expanded = True
'            blnFound = True
            'Exit Function
    '  End If
        
          ' Set childNode = NodeX.Child
          ' For i = 1 To NodeX.Children
          ' Call popFIND(childNode, findText, blnFound)
          ' Set childNode = childNode.Next
          ' Next
   
   
End Function

以上代碼解決自己的問題
3#
發(fā)表于 2010-8-17 11:44:47 | 只看該作者
loginwjd303 ,,你的樹挺好給我一份好嗎

您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2024-10-23 10:32 , Processed in 0.272744 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表