Jump to content

Recommended Posts

Posted

Hello forum

please allow me to re-open this almost 10 year old topic...

Should I have overlooked a more recent discussion about "How to call an event (only) when a treeview's item's checkbox is checked or unchecked" then please let me know.

By reading the discussion from 2009, I am wondering if REALLY it is required to

- intercept each and every event of $GUI_EVENT_PRIMARYDOWN anywhere on the GUI

- re-engineer (by means of GetMousePos and HitTest) which item (of the treeview) has been clicked

I would assume that a (much) more direct solution should exist to only intercept a treeview or even only certain treeviewitem events?

I see a wealth of functions in GuiTreeView.au3 (without too much talking however...) so there should be something more straight forward, no?

Thanks for your thoughts

THN

 

  • Moderators
Posted

THN,

Quote

please allow me to re-open this almost 10 year old topic

Please do not do this again. Just open a new thread (as I have now done for you) and link to the old thread.

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

 

Posted
23 hours ago, THN said:

I would assume that a (much) more direct solution should exist to only intercept a treeview or even only certain treeviewitem events?

I can't see _GUICtrlTreeView* functions at the moment, but I think that there is something that could fit your request in there.

By the way, if you shouldn't find what you're looking for, take a look here.

Those are the Notifaction Codes sent from a TreeView control.

You could intercept the click or the changed Notification Code from the TreeView, and work with them :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Posted

Here is the list of functions in GuiTreeView.au3:

; #CURRENT# =====================================================================================================================
; _GUICtrlTreeView_Add
; _GUICtrlTreeView_AddChild
; _GUICtrlTreeView_AddChildFirst
; _GUICtrlTreeView_AddFirst
; _GUICtrlTreeView_BeginUpdate
; _GUICtrlTreeView_ClickItem
; _GUICtrlTreeView_Create
; _GUICtrlTreeView_CreateDragImage
; _GUICtrlTreeView_CreateSolidBitMap
; _GUICtrlTreeView_Delete
; _GUICtrlTreeView_DeleteAll
; _GUICtrlTreeView_DeleteChildren
; _GUICtrlTreeView_Destroy
; _GUICtrlTreeView_DisplayRect
; _GUICtrlTreeView_DisplayRectEx
; _GUICtrlTreeView_EditText
; _GUICtrlTreeView_EndEdit
; _GUICtrlTreeView_EndUpdate
; _GUICtrlTreeView_EnsureVisible
; _GUICtrlTreeView_Expand
; _GUICtrlTreeView_ExpandedOnce
; _GUICtrlTreeView_FindItem
; _GUICtrlTreeView_FindItemEx
; _GUICtrlTreeView_GetBkColor
; _GUICtrlTreeView_GetBold
; _GUICtrlTreeView_GetChecked
; _GUICtrlTreeView_GetChildCount
; _GUICtrlTreeView_GetChildren
; _GUICtrlTreeView_GetCount
; _GUICtrlTreeView_GetCut
; _GUICtrlTreeView_GetDropTarget
; _GUICtrlTreeView_GetEditControl
; _GUICtrlTreeView_GetExpanded
; _GUICtrlTreeView_GetFirstChild
; _GUICtrlTreeView_GetFirstItem
; _GUICtrlTreeView_GetFirstVisible
; _GUICtrlTreeView_GetFocused
; _GUICtrlTreeView_GetHeight
; _GUICtrlTreeView_GetImageIndex
; _GUICtrlTreeView_GetImageListIconHandle
; _GUICtrlTreeView_GetIndent
; _GUICtrlTreeView_GetInsertMarkColor
; _GUICtrlTreeView_GetISearchString
; _GUICtrlTreeView_GetItemByIndex
; _GUICtrlTreeView_GetItemHandle
; _GUICtrlTreeView_GetItemParam
; _GUICtrlTreeView_GetLastChild
; _GUICtrlTreeView_GetLineColor
; _GUICtrlTreeView_GetNext
; _GUICtrlTreeView_GetNextChild
; _GUICtrlTreeView_GetNextSibling
; _GUICtrlTreeView_GetNextVisible
; _GUICtrlTreeView_GetNormalImageList
; _GUICtrlTreeView_GetParentHandle
; _GUICtrlTreeView_GetParentParam
; _GUICtrlTreeView_GetPrev
; _GUICtrlTreeView_GetPrevChild
; _GUICtrlTreeView_GetPrevSibling
; _GUICtrlTreeView_GetPrevVisible
; _GUICtrlTreeView_GetScrollTime
; _GUICtrlTreeView_GetSelected
; _GUICtrlTreeView_GetSelectedImageIndex
; _GUICtrlTreeView_GetSelection
; _GUICtrlTreeView_GetSiblingCount
; _GUICtrlTreeView_GetState
; _GUICtrlTreeView_GetStateImageIndex
; _GUICtrlTreeView_GetStateImageList
; _GUICtrlTreeView_GetText
; _GUICtrlTreeView_GetTextColor
; _GUICtrlTreeView_GetToolTips
; _GUICtrlTreeView_GetTree
; _GUICtrlTreeView_GetUnicodeFormat
; _GUICtrlTreeView_GetVisible
; _GUICtrlTreeView_GetVisibleCount
; _GUICtrlTreeView_HitTest
; _GUICtrlTreeView_HitTestEx
; _GUICtrlTreeView_HitTestItem
; _GUICtrlTreeView_Index
; _GUICtrlTreeView_InsertItem
; _GUICtrlTreeView_IsFirstItem
; _GUICtrlTreeView_IsParent
; _GUICtrlTreeView_Level
; _GUICtrlTreeView_SelectItem
; _GUICtrlTreeView_SelectItemByIndex
; _GUICtrlTreeView_SetBkColor
; _GUICtrlTreeView_SetBold
; _GUICtrlTreeView_SetChecked
; _GUICtrlTreeView_SetCheckedByIndex
; _GUICtrlTreeView_SetChildren
; _GUICtrlTreeView_SetCut
; _GUICtrlTreeView_SetDropTarget
; _GUICtrlTreeView_SetFocused
; _GUICtrlTreeView_SetHeight
; _GUICtrlTreeView_SetIcon
; _GUICtrlTreeView_SetImageIndex
; _GUICtrlTreeView_SetIndent
; _GUICtrlTreeView_SetInsertMark
; _GUICtrlTreeView_SetInsertMarkColor
; _GUICtrlTreeView_SetItemHeight
; _GUICtrlTreeView_SetItemParam
; _GUICtrlTreeView_SetLineColor
; _GUICtrlTreeView_SetNormalImageList
; _GUICtrlTreeView_SetScrollTime
; _GUICtrlTreeView_SetSelected
; _GUICtrlTreeView_SetSelectedImageIndex
; _GUICtrlTreeView_SetState
; _GUICtrlTreeView_SetStateImageIndex
; _GUICtrlTreeView_SetStateImageList
; _GUICtrlTreeView_SetText
; _GUICtrlTreeView_SetTextColor
; _GUICtrlTreeView_SetToolTips
; _GUICtrlTreeView_SetUnicodeFormat
; _GUICtrlTreeView_Sort
; ===============================================================================================================================

 

Honestly, none of them really catches my eye. I don't want to call a function, I need a certain function in my script to BE CALLED when a treeviewitem is (un)checked.

 

Let me know if you have another idea. Else I will keep searching on my side, no worries.

 

THN

 

  • Moderators
Posted

THN,

Within my ChooseFileFolder UDF I look for the checkboxes being clicked as follows:

- Native TreeView (GUICtrlCreateTreeView): Look for the $TVN_SELCHANGEDA/$TVN_SELCHANGEDW event within a WM_NOTIFY handler and then use GUICtrlGetHandle(GUICtrlRead) to get the handle of the particular item.

- UDF TreeView (_GUICtrlTreeView_Create): Look for the $NM_CLICK event with a WM_NOTIFY handler and then when received, loop through an array of current checkbox states to see if one has changed. I have never been able to get a less labour-intensive method, which I why I prefer to use the native control.

So either way you are going to need a WM_NOTIFY handler - might I suggest reading the GUIRegisterMsg tutorial in the Wiki if you are unfamiliar with Windows message handlers. Please do look at my UDF (the link in in my sig) to see how you might create one - and please do ask if you have any further 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

 

Posted

Thank you M23.

The most "clean" approach in my personal view is NOT by using GUIRegisterMsg with $WM_NOTIFY or $GUI_EVENT_PRIMARYDOWN, but rather with GUICtrlSetOnEvent for every newly created (added) treeview item. I then retrieve the item in question with _GUICtrlTreeView_GetSelection.

Like in this example.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         THN

 Script Function:
    Shows a folder tree, starting from $sPath

#ce ----------------------------------------------------------------------------

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

Local $sPath = @MyDocumentsDir & "\Downloads"
GUICreate("Folder tree under " & $sPath, 400, 300, -1, -1, BitOR($WS_SIZEBOX,$WS_SYSMENU))
GUISetState(@SW_SHOW)

Opt("GUIOnEventMode", 1)
# the following is needed because in GUIOnEventMode=1 the $GUI_EVENT_CLOSE event won't be passed to the GUIGetMsg message loop
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Local $hTreeView = GUICtrlCreateTreeView(5, 5, 388, 265, BitOR($TVS_CHECKBOXES, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP  + $GUI_DOCKBOTTOM)

_GUICtrlTreeView_BeginUpdate($hTreeView)
Folders($sPath, $hTreeView)
_GUICtrlTreeView_EndUpdate($hTreeView)

While True
   Sleep(100)
WEnd

Exit

Func _Exit()
   Exit
EndFunc

Func Folders($sPath, $hTV)
   Local $hItem = GUICtrlCreateTreeViewItem($sPath, $hTV)
   GUICtrlSetOnEvent(-1, "TreeViewItemOnEvent")
   Local $aFolders = _FileListToArray($sPath, "*", $FLTA_FOLDERS, True)
   If @error = 4 Then Return
   For $i = 1 To $aFolders[0]
      Folders($aFolders[$i], $hItem)
   Next
   GUICtrlSetState($hItem, $GUI_EXPAND)
EndFunc

Func TreeViewItemOnEvent()
   $hItem = _GUICtrlTreeView_GetSelection($hTreeView)
   MsgBox(0, "", _GUICtrlTreeView_GetText($hTreeView, $hItem) & " checked " & _
      _GUICtrlTreeView_GetChecked($hTreeView, $hItem))
EndFunc

CU

 

THN

Posted
Just now, THN said:

The most "clean" approach in my personal view is NOT by using GUIRegisterMsg with $WM_NOTIFY or $GUI_EVENT_PRIMARYDOWN, but rather with GUICtrlSetOnEvent for every newly created (added) treeview item. I then retrieve the item in question with _GUICtrlTreeView_GetSelection.

But not dynamic.
Your choice :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

  • THN changed the title to [SOLVED] Treeview checkbox OnEvent behaviour

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
  • Recently Browsing   0 members

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