Jump to content

Listview selected item colour when not in focus


Recommended Posts

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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