Jump to content

Recommended Posts

Posted

Hi, I wonder if there is a way to change the backgound color of a Listview in it's disabled state.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    GUICreate("listview items", 220, 250, 100, 200, -1)
    GUISetBkColor(0x00151515)

    Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150)
    Local $idButton = GUICtrlCreateButton("Disable /enable", 45, 170, 120, 20)
    Local $idItem1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
    Local $idItem2 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview)
    Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
    Local $iState

    GUICtrlSetColor($idListview, 0x0000FF00)
    GUICtrlSetBkColor($idListview, 0x00151515)

    GUISetState(@SW_SHOW)
    GUICtrlSetData($idItem2, "ITEM1")
    GUICtrlSetData($idItem3, "||COL33")

    $iState = 0
    GUICtrlSetState($idListview, 128)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idButton

                IF $iState = 0 Then
                    GUICtrlSetState($idListview, 64)
                    $iState = 1
                Else
                    GUICtrlSetState($idListview, 128)
                    $iState = 0
                EndIf



        EndSwitch
    WEnd
EndFunc

 

Posted

Maybe you could use _GUICtrlListView_SetItemImage to mark the line with an icon (see the example script in the help file for ... an example :) )

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted

There is no good way to change the background color in a disabled listview. But the usual workaround of placing the listview in a child window and then disable the child window instead of the listview works well in this situation:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Example()

Func Example()
    Local $hGui = GUICreate("listview items", 220, 250, 100, 200, -1)
    GUISetBkColor(0x00151515)

    Local $hChild = GUICreate( "", 200, 150, 10, 10, $WS_POPUP, $WS_EX_MDICHILD, $hGui )
    Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 0, 0, 200, 150)
    Local $idItem1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
    Local $idItem2 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview)
    Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
    GUICtrlSetColor($idListview, 0x0000FF00)
    GUICtrlSetBkColor($idListview, 0x00151515)
    GUISetState( @SW_SHOW, $hChild )
    GUISwitch( $hGui )

    Local $idButton = GUICtrlCreateButton("Disable /enable", 45, 170, 120, 20)
    Local $iState

    GUISetState(@SW_SHOW)
    GUICtrlSetData($idItem2, "ITEM1")
    GUICtrlSetData($idItem3, "||COL33")

    $iState = 0
    GUISetState( @SW_DISABLE, $hChild )
    ;GUICtrlSetState($idListview, 128)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idButton

                IF $iState = 0 Then
                    ;GUICtrlSetState($idListview, 64)
                    GUISetState( @SW_ENABLE, $hChild )
                    $iState = 1
                Else
                    ;GUICtrlSetState($idListview, 128)
                    Local $aIndex = _GUICtrlListView_GetSelectedIndices( $idListview, True )
                    _GUICtrlListView_SetItemSelected( $idListview, $aIndex[0] ? $aIndex[1] : -1, False )
                    GUISetState( @SW_DISABLE, $hChild )
                    $iState = 0
                EndIf
        EndSwitch
    WEnd
EndFunc

When the child window becomes disabled, the listview is also disabled. But the background color does not change.

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
×
×
  • Create New...