DarkBanana 0 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. Share this post Link to post Share on other sites
MikahS 92 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 & ScriptsMy Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4Feel free to use any of my code for your own use. Forum FAQ Share this post Link to post Share on other sites
DarkBanana 0 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? Share this post Link to post Share on other sites
water 2,359 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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
MikahS 92 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 & ScriptsMy Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4Feel free to use any of my code for your own use. Forum FAQ Share this post Link to post Share on other sites
DarkBanana 0 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. Share this post Link to post Share on other sites
MikahS 92 Posted August 17, 2015 Have a look at this link. Snips & ScriptsMy Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4Feel free to use any of my code for your own use. Forum FAQ Share this post Link to post Share on other sites
water 2,359 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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
DarkBanana 0 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. Share this post Link to post Share on other sites
LarsJ 1,013 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. 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 selectionsControl related: Hot-Track Enabled Toolbar Menu, Simulating a modeless Choose Color Dialog, Colors and fonts in TreeViewsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Share this post Link to post Share on other sites