Jump to content


Recommended Posts

I'd like to color the background of a _GUICtrlListView_InsertItem() created item, but I don't find an easy way ( with a function call ).
 Help =/ 

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

Func Example() ; fails, but is the one I'd like to use with _GUICtrlListView_InsertItem()
    Local $aItem, $idListview

    GUICreate("Color row FAIL", 300, 200)
    $idListview = GUICtrlCreateListView("", 2, 2, 294, 196)
    _GUICtrlListView_InsertColumn($idListview, 0, "Column 1", 100)

    ; Add items as such
    _GUICtrlListView_InsertItem($idListview, "Item 1", 0)
    _GUICtrlListView_InsertItem($idListview, "Item 2", 0)
    _GUICtrlListView_InsertItem($idListview, "Item 3", 0)

    $aItem = _GUICtrlListView_GetItem($idListview, 1)
    _GUICtrlListView_SetItemColor($idListview, 2, 0xF0)

    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func Example2() ; works
    Local $aItem, $idListview

    GUICreate("Color row OK", 300, 200)
    $idListview = GUICtrlCreateListView("Items", 2, 2, 294, 196)

    ; Add items as such
    GUICtrlCreateListViewItem("Row 1", $idListview)
    GUICtrlCreateListViewItem("Row 2", $idListview)
    GUICtrlCreateListViewItem("Row 3", $idListview)

    $aItem = _GUICtrlListView_GetItem($idListview, 1)
    _GUICtrlListView_SetItemColor($idListview, 2, 0xF0)

    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example2

Func _GUICtrlListView_SetItemColor($hListView, $iItem, $xColor) ; https://www.autoitscript.com/forum/topic/115871-set-color-line-guictrlcreatelistview-and-_guictrllistview/?do=findComment&comment=871218
    If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)
    $iReturn = GUICtrlSetColor(_GUICtrlListView_GetItemParam($hListView, $iItem), $xColor)
        Case $iReturn = 0
            Return SetError(1, 0, 0) ; Failure
        Case $iReturn = 1
            Return SetError(0, 0, 1) ; Success
EndFunc  ;==> END _GUICtrlListView_SetItemColor()


Link to post
Share on other sites
  • Moderators


As you have it working with the native GUICtrlCreateListViewitem, why do you need it to work with the UDF function? Why not just use the native function?


P.S. My GUIListViewEx UDF will do what you require, but it seems a bit overcomplicated when you have a working solution.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


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


Link to post
Share on other sites
Just now, Melba23 said:

you have it working with the native GUICtrlCreateListViewitem, why do you need it to work with the UDF function?

it's for a log entry in a listview. Using  _GUICtrlListView_InsertItem($lv,"text",0) , the next entry will show on top of the listview. ...unless there is a way to move the GUICtrlCreateListViewItem to the top. If there is no func. that can be created to ( seemingly ) simplify this, I'll try the  GUIListViewEx .
Thanks Melba23.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...