Jump to content

delayed guictrltreeview get index


Recommended Posts

hello =)

i am trying to get the index of the item selected.  i think the first click selects the treeview control so doesnt say which control is selected (not sure how to get around that either)

the second click is weird, because it says what was selected previously before selecting a new item

any ideas?

thank you in advance!

Link to comment
Share on other sites

  • Moderators

gcue,

So what have you tried that has not worked? I think I know the answer, but until you show me what you have done so far I cannot be sure.

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

ok setting the item first didnt help with the first issue either.. first click doesnt pick up 

i tried setting referencing the handle everytime instead of the control.. didnt work

 

Link to comment
Share on other sites

  • Moderators

gcue,

You cannot read the item clicked in the click detection handler, you need to wait until you are in the idle loop:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GUITreeview.au3>
#include <GUIMenu.au3>

; Create a flag to show when an item has been clicked
Global $fClick = False

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 200, 300, BitOR($TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)

GUISetState()

; Fill Treeview
_GUICtrlTreeView_BeginUpdate($hTreeView)
$iOverview = _GUICtrlTreeView_Add($hTreeView, 0, "Overview")

For $i = 1 To 15
    _GUICtrlTreeView_AddChild($hTreeView, $iOverview, "Item " & $i)
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
_GUICtrlTreeView_Expand($hTreeView)

; Register message
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Loop
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Test which item is selected at this point
    If $fClick Then
        $hItem = _GUICtrlTreeView_GetSelection($hTreeView)
        ConsoleWrite("Item Selected: " & _GUICtrlTreeView_GetText($hTreeView, $hItem) & " - " & $hItem & @CRLF)
        $fClick = False
    EndIf

WEnd

; Intercept the NOTIFY leassages
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    ; Read the data
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    ; See if it was our treeview
    Switch $hWndFrom
        Case $hTreeView
            ; Work out which item is under cursor
            $aPos = GUIGetCursorInfo($hGUI)
            $iIndex = _GUICtrlTreeView_HitTestItem($hTreeView, $aPos[0] - 10, $aPos[1] - 10)
            ; Look for code
            Switch $iCode
                Case $NM_CLICK
                    ; Set the flag to show we have clicked an item
                    $fClick = True
            EndSwitch
    EndSwitch

EndFunc   ;==>WM_NOTIFY

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

wow talk about cumbersome! =)

listview doesnt seem to have that problem - i realized totally different control but still =)

nevertheless, thank you very much!

hope you have a nice weekend

Edited by gcue
Link to comment
Share on other sites

  • Moderators

gcue,

if you use the native TreeView rather than the UDF one, you can do this:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GUITreeview.au3>

; Array to hold Item ControlIDs
Global $aItems[16]

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

$cTreeView = GUICtrlCreateTreeView(10, 10, 200, 300, BitOR($TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)

GUISetState()

; Fill Treeview
_GUICtrlTreeView_BeginUpdate($cTreeView)

$cOverview = GUICtrlCreateTreeViewItem("Overview", $cTreeView)

For $i = 1 To 15
    $aItems[$i] = GUICtrlCreateTreeViewItem("Item " & $i, $cOverview)
Next

_GUICtrlTreeView_EndUpdate($cTreeView)
_GUICtrlTreeView_Expand($cTreeView)

; Loop
While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cOverview
            ConsoleWrite(GUICtrlRead(GUICtrlRead($cTreeView), 1) & @CRLF)
        Case Else
            For $i = 1 To 15
                If $iMsg = $aItems[$i] Then
                    ConsoleWrite(GUICtrlRead(GUICtrlRead($cTreeView), 1) & @CRLF)
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

A bit simpler that the Windows handler version.

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...