Jump to content
Sign in to follow this  
RagsRevenge

Listview selected item colour when not in focus

Recommended Posts

RagsRevenge

Folks,

One of the features of a program I have written is that when you press Down or Up arrows while focused on an edit box, the selection in a listview is moved up and down. Functionally everything works ok.

I have one problem though, in that the colour of the selected item is very difficult to see, because it is a light grey on white. It is light grey because the listview isn't in focus. As soon as I tab to the listview, the selected item turns a nice deep blue.

Is there a way to have the selected item turn blue even when the listview isn't in focus?

One workaround I have is to change the background colour of the listview to something other than white, but I'm not a huge fan of this solution.

Here is a code extract from my program. I think it has been minimised to only contain what is necessary to show my problem, but apologies if there is a line or 2 in there which isn't striclty necessary.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Local $msg

Global $Form1 = GUICreate("Test Listview Selected but not in focus", 917, 351, -1, -1, BitOR($WS_POPUP, $WS_CAPTION))
Global $InFolderterms = GUICtrlCreateInput("", 110, 32, 693, 21)
Global $Label1 = GUICtrlCreateLabel("Input folder terms: ", 16, 32, 91, 17)
Global $ButDown = GUICtrlCreateButton("Down", 536, 32, 1, 1, 0)
GUICtrlSetState($ButDown, $GUI_HIDE)
Global $ButUp = GUICtrlCreateButton("Up", 536, 32, 1, 1, 0)
GUICtrlSetState($ButDown, $GUI_HIDE)
Global $ButExit = GUICtrlCreateButton("Exit", 536, 32, 1, 1, 0)
GUICtrlSetState($ButExit, $GUI_HIDE)
Global $lvDirectories = GUICtrlCreateListView("", 16, 72, 885, 257)

;GUICtrlSetBkColor(-1, 0x0AFFB0)
;Global $hLV_Handle = GUICtrlGetHandle($lvDirectories)

; Add columns
_GUICtrlListView_AddColumn($lvDirectories, "Items", 100)
_GUICtrlListView_AddColumn($lvDirectories, "SubItems 1", 100)
_GUICtrlListView_AddColumn($lvDirectories, "SubItems 2", 100)
_GUICtrlListView_AddColumn($lvDirectories, "SubItems 3", 100)

; Four column load
Dim $aItems[10][4]
For $iI = 0 To UBound($aItems) - 1
    $aItems[$iI][0] = "Item " & $iI
    $aItems[$iI][1] = "Item " & $iI & "-1"
    $aItems[$iI][2] = "Item " & $iI & "-2"
    $aItems[$iI][3] = "Item " & $iI & "-3"
Next
_GUICtrlListView_AddArray($lvDirectories, $aItems)
_GUICtrlListView_SetItemSelected($lvDirectories, 0)
GUISetState()
ControlFocus("[Active]", "", $InFolderterms)

Dim $AccelKeys[3][2]=[["{DOWN}", $ButDown], ["{UP}", $ButUp], ["^q", $ButExit]]
GUISetAccelerators($AccelKeys)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $ButDown
            _GUICtrlListView_SetItemSelected($lvDirectories, getSelectedIndex($lvDirectories) + 1)
            
        Case $ButUp
            _GUICtrlListView_SetItemSelected($lvDirectories, getSelectedIndex($lvDirectories) - 1)
        
        Case $ButExit
            Exit
            
    EndSwitch
    
    sleep(50)
WEnd

func getSelectedIndex($hLV)
    Local $LVIndex = _GUICtrlListView_GetSelectedIndices($hLV)
    
    Return Number($LVIndex)
EndFunc

Thanks in advance for any assistance,

D

Share this post


Link to post
Share on other sites
water

You could use _GUICtrlListView_SetItemImage to display an arrow or whatever left to the selected item.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.