syntech Posted February 1, 2010 Share Posted February 1, 2010 Hello! I would like to know if it is possible to detect checkbox changes in a TreeView without checking every single TreeViewItem? Or how can I find out if a TreeView has the focus? At the moment I'm consistently checking all TreeViewItems for changes, but this is very bad for the performance. That's why I would like to know if the TreeView is in use or not, because if not, then I can skip the iteration through all items and do it only when the user is actually 'using' the TreeView. Any suggestions? Link to comment Share on other sites More sharing options...
MvGulik Posted February 1, 2010 Share Posted February 1, 2010 (edited) whatever Edited February 7, 2011 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
syntech Posted February 1, 2010 Author Share Posted February 1, 2010 Thanks for your suggestion. I've never used Events till now, so I'll have a look at it. Link to comment Share on other sites More sharing options...
KaFu Posted February 1, 2010 Share Posted February 1, 2010 Take a look at the _GUICtrlTreeView_Create() example in the help-file (note that you'll have to replace some const figures by adding an A if they're found undeclared: e.g. $TVN_DELETEITEM => $TVN_DELETEITEMA). Using WM_NOTIFY you can detect if the treeview has been accessed and what has been done. As far as I can see these two: $NM_CLICK $TVN_KEYDOWN can be used to change checkbox state, either by mouse or keyboard. If you detect one of them, issue a _GUICtrlTreeView_GetChecked() command on the respective control handle and save the states to an array representing your treeview states... no need to loop anymore ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
syntech Posted February 1, 2010 Author Share Posted February 1, 2010 [..]Using WM_NOTIFY you can detect if the treeview has been accessed and what has been done. As far as I can see these two: $NM_CLICK $TVN_KEYDOWN can be used to change checkbox state, either by mouse or keyboard. If you detect one of them, issue a _GUICtrlTreeView_GetChecked() command on the respective control handle and save the states to an array representing your treeview states... no need to loop anymore ... This sounds very intersting, too! Thanks also to you for your suggestion. I've never used WM_NOTIFY before, so I'll check what it can do for me. Link to comment Share on other sites More sharing options...
syntech Posted February 1, 2010 Author Share Posted February 1, 2010 (edited) This is strange... Is _GUICtrlTreeView_GetChecked() broken or returns true in case of false and vice versa? Because when I check the box and output the return value of _GUICtrlTreeView_GetChecked() it says false. When I de-check the box it returns true... According to the help file it should return true for checked boxes and false for unchecked boxes. Is this a known issue? edit: I'm using Version 3.3.4.0 (the latest release) Edited February 1, 2010 by syntech Link to comment Share on other sites More sharing options...
KaFu Posted February 1, 2010 Share Posted February 1, 2010 Works fine for me... #include <GuiConstantsEx.au3> #include <GuiTreeView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> Local $hItem[6], $hRandomItem, $hTreeView, $edit, $string Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES) GUICreate("TreeView Get Checked", 620, 300) $edit = GUICtrlCreateEdit("", 400, 10, 200) $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 200, $iStyle, $WS_EX_CLIENTEDGE) GUISetState() _GUICtrlTreeView_BeginUpdate($hTreeView) For $x = 0 To UBound($hItem) - 1 $hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x + 1), $hTreeView) Next _GUICtrlTreeView_EndUpdate($hTreeView) ; Loop until user exits Do Sleep(500) $string = "" For $x = 0 To UBound($hItem) - 1 $string &= "Item " & $x & " is checked: " & _GUICtrlTreeView_GetChecked($hTreeView, $hItem[$x]) & @CRLF Next GUICtrlSetData($edit, $string) Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
syntech Posted February 1, 2010 Author Share Posted February 1, 2010 @KaFu: I found the problem. I was checking to early. I added the test to the $NM_CLICK case, but at this time the checkbox is not really set yet. Now I have to find out when I can add my routine, because $TVN_SELCHANGE does not work either, because I can select the checkbox of item 2 but item 1 is still highlighted, therefore no selection change has happend and the case is not true. I'll look if there is a possibility to make a selection change when I only click into the checkbox. Then it should work I hope. Link to comment Share on other sites More sharing options...
KaFu Posted February 1, 2010 Share Posted February 1, 2010 I took a deeper look... and it's much more complicated then I anticipated in the beginning ... take a look into my ShellTristateTreeView (see sig), there I use some code based on Holgers work to check the states. Is it really necessary to monitor each change? Alternatively you could wait for the message $NM_KILLFOCUS and then loop through all items to check if they're checked. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
syntech Posted February 2, 2010 Author Share Posted February 2, 2010 (edited) [..]Is it really necessary to monitor each change? Alternatively you could wait for the message $NM_KILLFOCUS and then loop through all items to check if they're checked. Well, I wanted to react to every checked TreeViewItem the moment it is checked/unchecked. But I'll try it with $NM_KILLFOCUS, maybe it's good enough... Edited February 2, 2010 by syntech Link to comment Share on other sites More sharing options...
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