Jump to content

_GUICtrlListView_SetItem_BkColor()


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>

Example()
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)
    GUISetState(@SW_SHOW)
    _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)
    GUICtrlSetBkColor($aItem[5],0xF0F0F0)
    _GUICtrlListView_SetItemColor($idListview, 2, 0xF0)

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

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

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

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

    $aItem = _GUICtrlListView_GetItem($idListview, 1)
    GUICtrlSetBkColor($aItem[5],0xF0F000)
    _GUICtrlListView_SetItemColor($idListview, 2, 0xF0)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
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)
    Select
        Case $iReturn = 0
            Return SetError(1, 0, 0) ; Failure
        Case $iReturn = 1
            Return SetError(0, 0, 1) ; Success
    EndSelect
EndFunc  ;==> END _GUICtrlListView_SetItemColor()

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • Moderators

argumentum,

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?

M23

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:

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

 

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

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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