Jump to content

Alternate color Listview items


Recommended Posts

As I have been struggling a bit with the way $GUI_BKCOLOR_LV_ALTERNATE works (couldn't find an example in the help file or the forum) I post a reproducer script for future reference so you can see how it works:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>

GUICreate("listview items", 220, 250, 100, 200, -1)
Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; alternate between the listview background color and the listview item background color
GUICtrlSetBkColor(-1, 0xDDEEFF) ; Set the background color for the listview
Local $idItem1 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview)
GUICtrlSetBkColor(-1, 0xFCF6EA) ; Set the background color for the listview item
Local $idItem2 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
GUICtrlSetBkColor(-1, 0xFCF6EA) ; Set the background color for the listview item
Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
GUICtrlSetBkColor(-1, 0xFCF6EA) ; Set the background color for the listview item
Local $idItem4 = GUICtrlCreateListViewItem("item4|col42|col43", $idListview)
GUICtrlSetBkColor(-1, 0xFCF6EA) ; Set the background color for the listview item
Local $idItem5 = GUICtrlCreateListViewItem("item5|col52|col53", $idListview)
GUICtrlSetBkColor(-1, 0xFCF6EA) ; Set the background color for the listview item
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Gives you:
Listview_alternate_color.thumb.png.aaf29

Edited by water

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

You can even change the color:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>

GUICreate("listview items", 220, 250, 100, 200, -1)
Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; alternate between the listview background color and the listview item background color
GUICtrlSetBkColor(-1, 0xDDEEFF) ; Set the background color for the listview
Local $idItem1 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview)
GUICtrlSetBkColor(-1, 0xFCF6EA) ; Set the background color for the listview item
Local $idItem2 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
GUICtrlSetBkColor(-1, 0xFCF6EA) ; Set the background color for the listview item
Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
GUICtrlSetBkColor(-1, 0xFCF6EA) ; Set the background color for the listview item
Local $idItem4 = GUICtrlCreateListViewItem("Now|change|color", $idListview)
GUICtrlSetBkColor(-1, 0xBBF6EA) ; Set the background color for the listview item
Local $idItem5 = GUICtrlCreateListViewItem("item5|col52|col53", $idListview)
GUICtrlSetBkColor(-1, 0xBBF6EA) ; Set the background color for the listview item
Local $idItem5 = GUICtrlCreateListViewItem("item6|col62|col63", $idListview)
GUICtrlSetBkColor(-1, 0xBBF6EA) ; Set the background color for the listview item
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Listview_alternate_color.thumb.png.94b8a

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

  • 6 months later...

I have added an additional example to the repository. Will be available with the next beta.

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...