Jump to content

Treeview Expand Event


snify
 Share

Recommended Posts

Hey there,

I have a simple GUI with a treeview and 4 Parent-Items.

Each Parent-Item has 1 Child Item. (just a info)

I need a Event (or something like this)

When I expand (I click the + button) the treeview,

I just want a msgbox with a text, which parentitem were opened.

Have someone a simple example code for me?

thank you

Greetz Snify

EDIT:

I am using GUIGETMSG() for my GUI

Edited by snify
Link to comment
Share on other sites

  • Moderators

snify,

First, welcome to the AutoIt forums.

I hope you do mind me pointing out that when you post here it always helps if you have had a go at solving your problem beforehand. Having some code to work on is a great help - and no-one here is too keen to help the "code it for me" brigade. >_<

However, as you were not to know that, take a look at this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>

Global $hTreeView, $fExpanded = 0
Global $ahRoot[5][2] = [[0, 0],[0, 0],[0, 0],[0, 0]]

$hGUI = GUICreate("Test", 220, 250)

$hTreeView = GUICtrlCreateTreeView(10, 10, 200, 200, -1, $WS_EX_CLIENTEDGE)

$ahRoot[1][0] = _GUICtrlTreeView_InsertItem($hTreeView, "RootItem1")
_GUICtrlTreeView_InsertItem($hTreeView, "SubItem1", $ahRoot[1][0])

$ahRoot[2][0] = _GUICtrlTreeView_InsertItem($hTreeView, "RootItem2")
_GUICtrlTreeView_InsertItem($hTreeView, "SubItem2", $ahRoot[2][0])

$ahRoot[3][0] = _GUICtrlTreeView_InsertItem($hTreeView, "RootItem3")
_GUICtrlTreeView_InsertItem($hTreeView, "SubItem3", $ahRoot[3][0])

$ahRoot[4][0] = _GUICtrlTreeView_InsertItem($hTreeView, "RootItem4")
_GUICtrlTreeView_InsertItem($hTreeView, "SubItem4", $ahRoot[4][0])

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
    $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            Exit
        Case $fExpanded = 1
            ; node closed so reset all nodes to current states
            For $i = 1 To 4
                If _GUICtrlTreeView_GetExpanded($hTreeView, $ahRoot[$i][0]) = True Then
                    $ahRoot[$i][1] = 1 ; set expanded flag
                Else
                    $ahRoot[$i][1] = 0 ; set closed flag
                EndIf
            Next
            $fExpanded = 0
        Case $fExpanded = 2
            ; node opened so check which changed
            For $i = 1 To 4
                If _GUICtrlTreeView_GetExpanded($hTreeView, $ahRoot[$i][0]) <> $ahRoot[$i][1] Then
                    $sText = _GUICtrlTreeView_GetText($hTreeView, $ahRoot[$i][0])
                EndIf
            Next
            MsgBox(0x40000, "+ Clicked", $sText)
            $fExpanded = 0
    EndSelect
WEnd

Func WM_Notify_Events($hWndGUI, $iMsgID, $wParam, $lParam)

    #forceref $hWndGUI, $iMsgID
    Local $tagNMHDR = DllStructCreate("int;int;int;int", $lParam)
    If @error Then Return
    Local $iEvent = DllStructGetData($tagNMHDR, 3)
    Select
        Case $wParam = $hTreeView
            Switch $iEvent
                Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA
                    $fExpanded = DllStructGetData($tagNMHDR, 4) ; 1 = node closed, 2 = node expanded
            EndSwitch
    EndSelect
    $tagNMHDR = 0
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_Notify_Events

I enjoyed getting that to work - and the rain has now stopped so the gardening calls!

M23

Edit: Minor code alteration

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 years later...

Hi,

I'm looking for the same; a notification when a treeview item is opened or closed.

So the notification should tell which treeview item it is, and whether it has been opened er closed.

In my search, I do see options for getting notified that an item within the treeview is opened or closed, but not which items was opened or closed.

Melba23 made some nice logic to determine which item it was, by checking on the old and the new state.

But much rather using such logic, I would like to use a direct notification from the OS which treeview item was opened/closed.

Does anyone know how this can be done?

Thanks!

vvhd

Link to comment
Share on other sites

  • Moderators

vvdh,

My coding skills have moved on a bit since then - you need to look for the $TVN_ITEMEXPANDEDW or $TVN_ITEMEXPANDEDA message like this (the example is taken from my ChooseFileFolder UDF):

Func _CFF_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    ; Create NMTREEVIEW structure
    Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
            "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
            "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
            "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
            "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
            "struct;long PointX;long PointY;endstruct", $lParam)
    Local $hWndFrom = DllStructGetData($tStruct, "hWndFrom") ; The control sending the message - the treeview itself
    Local $hItem = DllStructGetData($tStruct, "NewhItem")    ; The item within the treeview being expanded
    Local $iCode = DllStructGetData($tStruct, "Code")        ; The code used
    If $hWndFrom = $hCFF_TreeView Then
        Switch $iCode
            Case 0xFFFFFFFD ; $NM_DBLCLK
                ; Fire the dummy control
                GUICtrlSendToDummy($cCFF_DblClk_Dummy)
                ; Set flag
                $fCFF_ActiveTV = True
            Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA ; Something is being expanded/contracted <<<<<<<<<<<<<<<
                ; Check that expansion is not ongoing
                If GUICtrlRead($cCFF_Expand_Dummy) = 0 Then
                    ; Fire the dummy control
                    GUICtrlSendToDummy($cCFF_Expand_Dummy, $hItem)
                EndIf
                ; Set flag
                $fCFF_ActiveTV = True
        EndSwitch
    EndIf

EndFunc   ;==>_CFF_WM_NOTIFY_Handler
Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...