DarkBanana Posted August 17, 2015 Share Posted August 17, 2015 #include <Array.au3> #include <TreeViewConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUICtrlRead") $TreeVIew = GUICtrlCreateTreeView(10,10,200,200) ; $TVS_SHOWSELALWAYS doesn't work as intended $1 = GUICtrlCreateTreeViewItem("New",$TreeView) $2 = GUICtrlCreateTreeViewItem("Tree",$1) GUICtrlCreateTreeViewItem("Leaf",$2) GUISetState(@SW_SHOW) GUICtrlCreateDate("",10,250,100,100) Do $idMsg = GUIGetMsg() Until $idMsg = $GUI_EVENT_CLOSE EndFuncHey there,I would like to know how to keep my treeview selection if my treeview control loses focus. I tried $TVS_SHOWSELALWAYS but it doesn't seem to work.And is it possible to keep my selection even if I change to another child gui? Thanks in advance. Link to comment Share on other sites More sharing options...
MikahS Posted August 17, 2015 Share Posted August 17, 2015 It is still selected, it just loses focus on the control. Which, greys it out and does not lose the selection. If the window is given focus again it will be on the same selection. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
DarkBanana Posted August 17, 2015 Author Share Posted August 17, 2015 Well thanks for clarifying.I would like to keep the blue selection. So I can clearly see what I have selected previously.Is there a nice solution for this. Or do I need to use a workaround? Link to comment Share on other sites More sharing options...
water Posted August 17, 2015 Share Posted August 17, 2015 I wouldn't use a workaround. Greying out a selection in a listview without focus is the way Windows works. And it is what users have gotten used to. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
MikahS Posted August 17, 2015 Share Posted August 17, 2015 My pleasure and I would agree with @water on this one. The only way I have seen anyone modify this is with VB or C#. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
DarkBanana Posted August 17, 2015 Author Share Posted August 17, 2015 I don't really care what "users" have gotten used to. So I need to use a workaround.Let's see where it takes me.Thanks anyway. Link to comment Share on other sites More sharing options...
MikahS Posted August 17, 2015 Share Posted August 17, 2015 Have a look at this link. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
water Posted August 17, 2015 Share Posted August 17, 2015 I don't really care what "users" have gotten used to.Let me reword it: Greying out the control is a standard set up by Microsoft. So why change it? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
DarkBanana Posted August 17, 2015 Author Share Posted August 17, 2015 expandcollapse popup#include <Array.au3> #include <TreeViewConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiTreeView.au3> #include <ColorConstants.au3> #include <WindowsConstants.au3> Example() Func Example() GUICreate("My GUICtrlRead") $CurSel = "" Global $TreeVIew = GUICtrlCreateTreeView(10,10,200,200) ; $TVS_SHOWSELALWAYS doesn't work as intended Global $1 = GUICtrlCreateTreeViewItem("New",$TreeView) Global $2 = GUICtrlCreateTreeViewItem("Tree",$1) GUICtrlCreateTreeViewItem("Leaf",$2) GUICtrlCreateButton("",10,250,100,100) GUICtrlCreateInput("",250,10,100,100) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case -3 Exit EndSwitch WEnd EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview $hWndTreeview = $TreeView If Not IsHWnd($TreeView) Then $hWndTreeview = GUICtrlGetHandle($TreeView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW Case $NM_KILLFOCUS $Selected = _GUICtrlTreeView_GetSelection($TreeView) GUICtrlSetBkColor($1,0x3399ff) ; GUICtrlSetBkColor($Selected,0x3399ff) doesn't work GUICtrlSetColor($1,0xFFFFFF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYThis is what I got so far. But I can't change the background color of the currently selected item. The handle returned by ..._GetSelection doesn't seem to work.And in the TreeView UDF there's no function to change the color of a specific item or is there?@Water I want the bright blue color so I can clearly see what is selected. I can barely see the grey background color. That's why I want to change it. Link to comment Share on other sites More sharing options...
LarsJ Posted August 18, 2015 Share Posted August 18, 2015 The color of the selected item is controlled by Windows. With and without focus. Remove the selected state of the item and you can set the color yourself.You need the item controlId to set the color with GUICtrlSetBkColor. Not the item handle. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions 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