gcue Posted July 1, 2016 Posted July 1, 2016 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!
Moderators Melba23 Posted July 1, 2016 Moderators Posted July 1, 2016 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
gcue Posted July 1, 2016 Author Posted July 1, 2016 i tried pre-selecting an item to help the first issue but that didnt help with the second.. not sure what to try for second issue
gcue Posted July 1, 2016 Author Posted July 1, 2016 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
Moderators Melba23 Posted July 1, 2016 Moderators Posted July 1, 2016 gcue, You cannot read the item clicked in the click detection handler, you need to wait until you are in the idle loop: expandcollapse popup#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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
gcue Posted July 1, 2016 Author Posted July 1, 2016 (edited) 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 July 1, 2016 by gcue
Moderators Melba23 Posted July 2, 2016 Moderators Posted July 2, 2016 gcue, if you use the native TreeView rather than the UDF one, you can do this: expandcollapse popup#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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now