Jump to content
Sign in to follow this  
lsakizada

Is it possible set color of single listview item?

Recommended Posts

lsakizada

I want alternate color in List View but I was unable to set it properly.

Can someone help to create functions like.

_GUICtrlListView_SetItemColor

_GUICtrlListView_SetItemBkColor

thanks!


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
water

I use the following code to change the color of every second entry

GUICtrlCreateListViewItem("itemtext", $hGUIUserList)
If Mod($iRec, 2) = 0 Then GUICtrlSetBkColor(-1, 0xD0DEC7)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
lsakizada

I use the following code to change the color of every second entry

GUICtrlCreateListViewItem("itemtext", $hGUIUserList)
If Mod($iRec, 2) = 0 Then GUICtrlSetBkColor(-1, 0xD0DEC7)
Thanks for the rely, it is not working for me.

I found this thread which helped me:

http://www.autoitscript.com/forum/index.ph...mp;#entry675962

Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
Melba23

lsakizada,

The syntax for alternate coloured ListViews is not easy to get from the Help file:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#Include <GuiListView.au3>

$hWin = GUICreate("Alt Coloured ListView", 500, 500, -1, -1)
    GUISetBkColor(0xCECECE)
$hList = GUICtrlCreateListView ("This is an alternate coloured ListView", 10, 10, 480, 480, $LVS_SINGLESEL)
; Set up alt line colouring
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
    _GUICtrlListView_SetColumnWidth($hList, 0, $LVSCW_AUTOSIZE_USEHEADER)
GUISetState()

For $i = 1 to 10
    GUICtrlCreateListViewItem("Item " & $i, $hList)
; Set up alt line colouring
        GUICtrlSetBkColor(-1, 0xCCFFCC)
    Next

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

M23

Edit: If you really want to customise your ListView then look here.

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
RagsRevenge

lsakizada,

The syntax for alternate coloured ListViews is not easy to get from the Help file:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#Include <GuiListView.au3>

$hWin = GUICreate("Alt Coloured ListView", 500, 500, -1, -1)
    GUISetBkColor(0xCECECE)
$hList = GUICtrlCreateListView ("This is an alternate coloured ListView", 10, 10, 480, 480, $LVS_SINGLESEL)
; Set up alt line colouring
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
    _GUICtrlListView_SetColumnWidth($hList, 0, $LVSCW_AUTOSIZE_USEHEADER)
GUISetState()

For $i = 1 to 10
    GUICtrlCreateListViewItem("Item " & $i, $hList)
; Set up alt line colouring
        GUICtrlSetBkColor(-1, 0xCCFFCC)
    Next

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

M23

Edit: If you really want to customise your ListView then look here.

Is it possible to use the alternate background colour when using _GuiCtrlListview_AddArray?

I can't figure it out, seeing as I'm not creating individual listviewItems, so don't have an ID for assigning background colour to the item.

Any help, greatly appreciated.

D

Share this post


Link to post
Share on other sites
RagsRevenge

Is it possible to use the alternate background colour when using _GuiCtrlListview_AddArray?

I can't figure it out, seeing as I'm not creating individual listviewItems, so don't have an ID for assigning background colour to the item.

Any help, greatly appreciated.

D

This is a snippet of what I've tried (which isn't working)

This is a snippet from a function which is passed the listview as $control, and the array as $aContent.

My fear is that I am misunderstanding the _GUICtrlListView_GetItemParam function. I *think* that it will return the control ID for a listviewItem associated with the specified line.

GUICtrlSetFont($control, 11)
    GUICtrlSetBkColor($control, $GUI_BKCOLOR_LV_ALTERNATE)  ;set alternate colours for listviewitems
    ;GUICtrlSetBkColor($control, 0xFFFFFF)
    
    _GUICtrlListView_AddArray($control, $aContent)
    
        $numItems = _GUICtrlListView_GetItemCount(GUICtrlGetHandle($control)) - 1
    for $i = $numItems to 0 Step -1
    $listviewItem = _GUICtrlListView_GetItemParam(GUICtrlGetHandle($control), $i)
        if $listviewItem Then
            GUICtrlSetBkColor($listviewItem, 0xECE9D8)
        EndIf
    Next

I have this product nearly fully tested so don't want to introduce total unknowns by using the UDF you linked to above.

Thanks,

D

Share this post


Link to post
Share on other sites
RagsRevenge

My fear is that I am misunderstanding the _GUICtrlListView_GetItemParam function. I *think* that it will return the control ID for a listviewItem associated with the specified line.

So, I *think* I misunderstood waht _GUICtrlListView_GetItemParam does. In its stead, I'm using _GUICtrlListView_MapIndexToID

GUICtrlSetFont($control, 11)
    GUICtrlSetBkColor($control, $GUI_BKCOLOR_LV_ALTERNATE)  ;set alternate colours for listviewitems
    ;GUICtrlSetBkColor($control, 0xFFFFFF)
    
    _GUICtrlListView_AddArray($control, $aContent)
    
        $numItems = _GUICtrlListView_GetItemCount(GUICtrlGetHandle($control)) - 1
    for $i = $numItems to 0 Step -1
    $listviewItem = _GUICtrlListView_MapIndexToID(GUICtrlGetHandle($control), $i)
        if $listviewItem Then
            GUICtrlSetBkColor($listviewItem, 0xECE9D8)
        EndIf
    Next

But for some reason, my listview is remaining unchanged, and a couple of totally unrelated labels are having their background set.

Any help greatly appreciated, and apologies for the ongoing soliloquy.

D

Share this post


Link to post
Share on other sites
Gideon

Why did I need to google this, because color was removed in the query?


Many times you need to think like hobby-bob:')

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  

×