Public Function GetLevel() As Long Dim nod1 As Node Dim nLevel As Integer Set nod1 = Tv.SelectedItem Do While (nod1 Is Nothing) = False nLevel = nLevel + 1 Set nod1 = nod1.Parent Loop GetLevel = nLevel End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Enum HORZ_VERT SB_HORZ = 0& SB_VERT = 1& End Enum Public Enum SIF_MASK SIF_RANGE = &H1& SIF_PAGE = &H2& SIF_POS = &H4& SIF_DISABLENOSCROLL = &H8& SIF_TRACKPOS = &H10& SIF_ALL = SIF_RANGE Or SIF_PAGE Or SIF_POS End Enum Private Type SCROLLINFO cbSize As Long fMask As SIF_MASK nMin As Long nMax As Long nPage As Long nPos As Long nTrackPos As Long End Type Private Declare Function GetScrollInfo Lib "user32" _ (ByVal hwnd As Long, ByVal fnBar As HORZ_VERT, lpScrollInfo As _ SCROLLINFO) As Long Private Declare Function SetScrollInfo Lib "user32" _ (ByVal hwnd As Long, ByVal fnBar As HORZ_VERT, lpcScrollInfo As _ SCROLLINFO, ByVal fRedraw As Boolean) As Long
Dim m_tagSCROLLINFO As SCROLLINFO m_tagSCROLLINFO.cbSize = LenB(m_tagSCROLLINFO) m_tagSCROLLINFO.fMask = SIF_ALL Call GetScrollInfo(Tv.hwnd, SB_VERT, m_tagSCROLLINFO)
nMax donne le nombre maximum de Lignes à afficher nPos donne la position de la Scrollbar nPage donne le nombre de Ligne du Treeview La position mini de la Scrollbar est zéro La position maxi de la Scrollbar est nMax - nPage +1
On peut agir sur les deux Scrollbars avec SB_HORZ ou SB_VERT avec GetScrollInfo on obtient les renseignements avec SetScrollInfo on doit pouvoir les modifier
Private Const WM_HSCROLL = &H114 Private Const WM_VSCROLL = &H115 Private Const SB_LEFT = 6 Private Const SB_RIGHT = 7 Private Const TV_FIRST As Long = &H1100 Private Const TVM_DELETEITEM As Long = (TV_FIRST + 1) Private Const TVM_GETITEMRECT As Long = (TV_FIRST + 4) Private Const TVM_GETNEXTITEM As Long = (TV_FIRST + 10) Private Const TVM_SELECTITEM As Long = (TV_FIRST + 11) Private Const TVM_GETITEM As Long = (TV_FIRST + 12) Private Const TVM_SETITEM As Long = (TV_FIRST + 13) Private Const TVM_GETEDITCONTROL As Long = (TV_FIRST + 15) Private Const TVM_HITTEST As Long = (TV_FIRST + 17) '@@ v02.02.00 Private Enum TVGN_Flags TVGN_ROOT = &H0 TVGN_NEXT = &H1 TVGN_PREVIOUS = &H2 TVGN_PARENT = &H3 TVGN_CHILD = &H4 TVGN_FIRSTVISIBLE = &H5 TVGN_NEXTVISIBLE = &H6 TVGN_PREVIOUSVISIBLE = &H7 TVGN_DROPHILITE = &H8 TVGN_CARET = &H9 TVGN_LASTVISIBLE = &HA End Enum Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function SendMessageAny Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long Private Sub SetFirstVisibleNode(ByVal Node As MSComctlLib.Node) ' '## Set the first visible Node of a TreeView control ' Dim hItem As Long Dim selNode As MSComctlLib.Node LockWindowUpdate Treeview.hwnd With Treeview '## Remember the node currently selected Set selNode = .SelectedItem '## Make the Node the select Node in the control Set .SelectedItem = Node '## Now we can get its handle hItem = SendMessageAny(.hwnd, TVM_GETNEXTITEM, TVGN_CARET, ByVal 0&) '## Restore node that was selected Set .SelectedItem = selNode '## Make it the fist visible Node SendMessageLong .hwnd, TVM_SELECTITEM, TVGN_FIRSTVISIBLE, hItem SendMessageLong .hwnd, WM_HSCROLL, SB_LEFT, 0 End With LockWindowUpdate 0 End Sub
Public Sub SelectedFirstVisible(trv As TreeView) '## Make the .SelectedItem of a TreeView control the first visible Dim hItem As Long Dim m_tagSCROLLINFO As SCROLLINFO Dim iLeft As Integer With trv If Not (.SelectedItem Is Nothing) Then LockWindowUpdate .hwnd '## Now we can get its handle hItem = SendMessageAny(.hwnd, TVM_GETNEXTITEM, TVGN_CARET, ByVal 0&) '## Make it the fist visible Node SendMessageLong .hwnd, TVM_SELECTITEM, TVGN_FIRSTVISIBLE, hItem ' Calcul du décalage à droite selon le niveau courant de la hiérarchie Select Case .SelectedItem.Text Case NIV_SEC: iLeft = 0 Case NIV_REG: iLeft = 34 Case NIV_DEP: iLeft = 68 Case NIV_FIC: iLeft = 102 End Select m_tagSCROLLINFO.cbSize = LenB(m_tagSCROLLINFO) m_tagSCROLLINFO.fMask = SIF_POS m_tagSCROLLINFO.nPos = iLeft SetScrollInfo .hwnd, SB_HORZ, m_tagSCROLLINFO, True LockWindowUpdate 0 End If End With End Sub