Sign in to follow this  
Followers 0
mozart90

Color of listview items ...

9 posts in this topic

#1 ·  Posted (edited)

Hi,

is it possible to color some items in a listview - the items of the listview do already exist?

eg first ist red, second is black)

(I'm interested in the forecolor not the backgroundcolor)

Best regards

Mozart90

Edited by mozart90

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>

GUICreate('', 230, 156)

$btn1 = GUICtrlCreateButton('Item 1', 10, 120, 50, 26)
$btn2 = GUICtrlCreateButton('Item 2', 70, 120, 50, 26)
$btn3 = GUICtrlCreateButton('Item 3', 130, 120, 50, 26)
$HL = GUICtrlCreateButton('HL', 190, 120, 30, 26)


$lv = GUICtrlCreateListView('Some Column', 10, 10, 210, 100)

$lvi1 = GUICtrlCreateListViewItem('Some Item 1', $lv)
$lvi2 = GUICtrlCreateListViewItem('Some Item 2', $lv)
$lvi3 = GUICtrlCreateListViewItem('Some Item 3', $lv)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn1
            GUICtrlSetBkColor($lvi1, 0xFF0000)
        Case $btn2
            GUICtrlSetBkColor($lvi2, 0x00FF00)
        Case $btn3
            GUICtrlSetBkColor($lvi3, 0x0000FF)
        Case $HL
            GUICtrlSetBkColor(GUICtrlRead($lv), 0xFFFF00)
    EndSwitch
WEnd

The HL button colors what's highlighted.

Share this post


Link to post
Share on other sites

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn1
            GUICtrlSetBkColor($lvi1, 0xFF0000)
        Case $btn2
            GUICtrlSetBkColor($lvi2, 0x00FF00)
        Case $btn3
            GUICtrlSetBkColor($lvi3, 0x0000FF)
        Case $HL
            GUICtrlSetBkColor(GUICtrlRead($lv), 0xFFFF00)
    EndSwitch
You were close. The OP said:

(I'm interested in the forecolor not the backgroundcolor)

Just changing GuiCtrlSetBkColor() to GuiCtrlSetColor() does it though...

:whistle:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I was actually assuming by "background" that the OP was referring to a single, uniform color of the whole listview (eg. GUICtrlSetBkColor($lv, 0xFF0000)). So what I posted was, in fact, what I intended to be the answer. I figured if the OP meant text, he would have said that instead of foreground.

If he actually did mean the text color, then yes, remove the "Bk."

Edited by xcal

Share this post


Link to post
Share on other sites

I was actually assuming by "background" that the OP was referring to a single, uniform color of the whole listview (eg. GUICtrlSetBkColor($lv, 0xFF0000)). So what I posted was, in fact, what I intended to be the answer. I figured if the OP meant text, he would have said that instead of foreground.

If he actually did mean the text color, then yes, remove the "Bk."

Good point. Just for giggles, I modded to change the color in three places, the Bk of the LV, the Bk of the item, and the text:

#include <GUIConstants.au3>

GUICreate('', 230, 156)

$btn1 = GUICtrlCreateButton('Item 1', 10, 120, 50, 26)
$btn2 = GUICtrlCreateButton('Item 2', 70, 120, 50, 26)
$btn3 = GUICtrlCreateButton('Item 3', 130, 120, 50, 26)
$HL = GUICtrlCreateButton('HL', 190, 120, 30, 26)

$lv = GUICtrlCreateListView('Some Column', 10, 10, 210, 100)
GUICtrlSetBkColor(-1, 0x00FFFF)

$lvi1 = GUICtrlCreateListViewItem('Some Item 1', $lv)
$lvi2 = GUICtrlCreateListViewItem('Some Item 2', $lv)
$lvi3 = GUICtrlCreateListViewItem('Some Item 3', $lv)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn1
            GUICtrlSetBkColor($lvi1, 0xFF0000)
        Case $btn2
            GUICtrlSetBkColor($lvi2, 0x00FF00)
        Case $btn3
            GUICtrlSetBkColor($lvi3, 0x0000FF)
        Case $HL
            GUICtrlSetColor(GUICtrlRead($lv), 0xFFFF00)
    EndSwitch
WEnd

:whistle:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

This question relates to Beta version

When using _GUICtrlListView_MapIndexToID() and then later using this to set the BKcolor does not work. Does anyone know why and how to achieve using MapIndexToID() to set color.

#include <GUIConstants.au3>
#include <GUIListView.au3>

GUICreate('', 230, 156)

$btn1 = GUICtrlCreateButton('Item 1', 10, 120, 50, 26)
$btn2 = GUICtrlCreateButton('Item 2', 70, 120, 50, 26)
$btn3 = GUICtrlCreateButton('Item 3', 130, 120, 50, 26)
$HL = GUICtrlCreateButton('HL', 190, 120, 30, 26)


$lv = GUICtrlCreateListView('Some Column', 10, 10, 210, 100)

$lvi1 = GUICtrlCreateListViewItem('Some Item 1', $lv)
$lvi2 = GUICtrlCreateListViewItem('Some Item 2', $lv)
$lvi3 = GUICtrlCreateListViewItem('Some Item 3', $lv)

GUISetState()

Local $ID = _GUICtrlListView_MapIndexToID($lv,1)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn1
            GUICtrlSetBkColor($ID, 0xFF0000)
        Case $btn2
            GUICtrlSetBkColor($lvi2, 0x00FF00)
        Case $btn3
            GUICtrlSetBkColor($lvi3, 0x0000FF)
        Case $HL
            GUICtrlSetBkColor(GUICtrlRead($lv), 0xFFFF00)
    EndSwitch
WEnd

A decision is a powerful thing

Share this post


Link to post
Share on other sites

This question relates to Beta version

When using _GUICtrlListView_MapIndexToID() and then later using this to set the BKcolor does not work. Does anyone know why and how to achieve using MapIndexToID() to set color.

Run this to see why:

#include <GUIConstants.au3>
#include <GUIListView.au3>

GUICreate('', 230, 156)
$lv = GUICtrlCreateListView('Some Column', 10, 10, 210, 100)
$lvi1 = GUICtrlCreateListViewItem('Some Item 1', $lv)
$lvi2 = GUICtrlCreateListViewItem('Some Item 2', $lv)
$lvi3 = GUICtrlCreateListViewItem('Some Item 3', $lv)
GUISetState()

Local $ID = _GUICtrlListView_MapIndexToID($lv,1)

ConsoleWrite("Debug:" & @LF & _
        @TAB & "$lv = " & $lv & @LF & _
        @TAB & "$lvi1 = " & $lvi1 & @LF & _
        @TAB & "$lvi2 = " & $lvi2 & @LF & _
        @TAB & "$lvi3 = " & $lvi3 & @LF & _
        @TAB & "$ID = " & $ID & @LF)

The internal ID of an item in a ListView is not the same as the AutoIt ControlID, so you can't use it in AutoIt's built-in GuiCtrlSet* functions.

<_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Run this to see why:

#include <GUIConstants.au3>
#include <GUIListView.au3>

GUICreate('', 230, 156)
$lv = GUICtrlCreateListView('Some Column', 10, 10, 210, 100)
$lvi1 = GUICtrlCreateListViewItem('Some Item 1', $lv)
$lvi2 = GUICtrlCreateListViewItem('Some Item 2', $lv)
$lvi3 = GUICtrlCreateListViewItem('Some Item 3', $lv)
GUISetState()

Local $ID = _GUICtrlListView_MapIndexToID($lv,1)

ConsoleWrite("Debug:" & @LF & _
        @TAB & "$lv = " & $lv & @LF & _
        @TAB & "$lvi1 = " & $lvi1 & @LF & _
        @TAB & "$lvi2 = " & $lvi2 & @LF & _
        @TAB & "$lvi3 = " & $lvi3 & @LF & _
        @TAB & "$ID = " & $ID & @LF)

The internal ID of an item in a ListView is not the same as the AutoIt ControlID, so you can't use it in AutoIt's built-in GuiCtrlSet* functions.

<_<

GOOOOOOOOD EXAMPLE and explanation. So is there no way to retrieve the AutoIt ControlID with the MapIndexToID() or to at least achieve the coloring of a listview item with MapIndexToID() ?

EDIT

In my script, I'm actually using _GUICtrlListView_AddItem() and not GUICtrlCreateListViewItem()

Notice how it won't change the first (zero) item.

#include <GUIConstants.au3>
#include <GUIListView.au3>

GUICreate('Test', 230, 156)

$btn1 = GUICtrlCreateButton('Item 1', 10, 120, 50, 26)
$btn2 = GUICtrlCreateButton('Item 2', 70, 120, 50, 26)
$btn3 = GUICtrlCreateButton('Item 3', 130, 120, 50, 26)
$HL = GUICtrlCreateButton('HL', 190, 120, 30, 26)


$lv = GUICtrlCreateListView('Some Column', 10, 10, 210, 100)
$lvi1 = _GUICtrlListView_AddItem($lv,'Some Item 1')
;~ $lvi1 = GUICtrlCreateListViewItem('Some Item 1', $lv)
$lvi2 = GUICtrlCreateListViewItem('Some Item 2', $lv)
$lvi3 = GUICtrlCreateListViewItem('Some Item 3', $lv)

GUISetState()

Local $totalItems = _GUICtrlListView_GetItemCount($lv)
Local $itemsIndexArray[$totalItems]
For $_a = 0 To $totalItems-1
    $itemsIndexArray[$_a] = $_a
Next


;Local $mapID = _GUICtrlListView_MapIndexToID($lv,Number('1'));Number is used to demonstrate what must be done if you're using a string (for some weird reason)
;~ Local $mapID = _GUICtrlListView_MapIndexToID($lv,$itemsIndexArray[0])
Local $mapID = _GUICtrlListView_MapIndexToID($lv,$lvi1+1);Number is used to because an array position is used


Local $mapIndex = _GUICtrlListView_MapIDToIndex($lv,$mapID)
Local $_array = _GUICtrlListView_GetItem($lv, $mapIndex)
Local $ID = $_array[5]
ConsoleWrite($lvi1 &' vs ' & $ID & @CRLF)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn1
            GUICtrlSetBkColor($ID, 0xFF0000)
        Case $btn2
            GUICtrlSetBkColor($lvi2, 0x00FF00)
        Case $btn3
            GUICtrlSetBkColor($lvi3, 0x0000FF)
        Case $HL
            GUICtrlSetBkColor(GUICtrlRead($lv), 0xFFFF00)
    EndSwitch
WEnd
Edited by JohnBailey

A decision is a powerful thing

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  
Followers 0