Jump to content
Sign in to follow this  
Furek86

TreeView selected item

Recommended Posts

Furek86

hey guys,

I am having an issue with my treeview control. I want to get the text of a selected item, but only when I click on THE item, not when I click on the expand symbol (+). Could anyone help? Or if it was already raised and resolved, point me to the right thread?

$treeViewOUs = GUICtrlCreateTreeView(16, 232, 209, 345, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
Global $hTreeView = GUICtrlGetHandle($treeViewOUs)
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local $tNMHDR, $IdFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$IdFrom = DllStructGetData($tNMHDR, "IdFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
     Switch $hWndFrom
     Case $hTreeView
         Switch $iCode
             Case $NM_CLICK
     ConsoleWrite(_GUICtrlTreeView_GetText($hTreeView,_GUICtrlTreeView_GetSelection($hTreeView)) & @CRLF)
         EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY

Share this post


Link to post
Share on other sites
Melba23

Furek86,

I would do it like this - the "click" comes first and arms an Adlib function. If if it is followed almost immediately (withint 5 ms on my machine) by an "expand/contract" message we cancel the Adlib function: ;)

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

$fClicked = False

$hGUI = GUICreate("Test", 500, 500)

$treeViewOUs = GUICtrlCreateTreeView(16, 32, 209, 345, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
Global $hTreeView = GUICtrlGetHandle($treeViewOUs)
$generalitem = GUICtrlCreateTreeViewItem("General", $treeViewOUs)
$displayitem = GUICtrlCreateTreeViewItem("Display", $treeViewOUs)
$aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
$compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
GUICtrlCreateTreeViewItem("User", $generalitem)
GUICtrlCreateTreeViewItem("Resolution", $displayitem)
GUICtrlCreateTreeViewItem("Other", $displayitem)

$cClk_Dummy = GUICtrlCreateDummy()

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func _Read()
    ConsoleWrite(_GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) & " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" & @CRLF)
    AdlibUnRegister("_Read")
EndFunc   ;==>_Read

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

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hTreeView
            Switch $iCode
                Case $NM_CLICK
                    AdlibRegister("_Read", 20)
                    ConsoleWrite("Registered" & @CRLF)
                Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA
                    AdlibUnRegister("_Read")
                    ConsoleWrite("Unregistered" & @CRLF)
            EndSwitch
    EndSwitch
EndFunc   ;==>_WM_NOTIFY

I have left the ConsoleWrite lines in so you can see what is happening. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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
Sign in to follow this  

×