Jump to content

_GUICtrlListView set line color?


Recommended Posts

people, how to i put new line color in GUICtrlListView ?

i dont use the setbkcolor because i'm using the

_GUICtrlListView_AddArray()
to add the data in CtrlListView

I wanted to leave a white line and a gray

any ideias?

thankyou so much!

Edited by darkshark
Link to comment
Share on other sites

  • Moderators

darkshark,

I can see no way to get the alternate line colouring while using that UDF function. But it is not too difficult to write something to add an array to a ListView - and then you can add the line colouring as well: :x

#include <GUIConstantsEx.au3>

Global $aItems[4][2] = [["Item 1", "SubItem 1"], ["Item 2", "SubItem 2"], ["Item 3", "SubItem 3"], ["Item 4", "SubItem 4"]]

$hGUI = GUICreate("Test", 500, 500)

$hLV = GUICtrlCreateListView("Col 1     |Col 2", 10, 10, 200, 200)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)

For $i = 0 To UBound($aItems) - 1
    ; Clear the item string
    $sItem = ""
    For $j = 0 To UBound($aItems, 2) - 1
        ; Add each item and subitem to the string
        $sItem &= $aItems[$i][$j] & "|"
    Next
    ; Add the item string
    GUICtrlCreateListViewItem($sItem, $hLV)
    ; Set the alternate line colour
    GUICtrlSetBkColor(-1, 0xCCCCCC)
Next

GUISetState()

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

Any use? :P

M23

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

darkshark,

I can see no way to get the alternate line colouring while using that UDF function. But it is not too difficult to write something to add an array to a ListView - and then you can add the line colouring as well: :x

#include <GUIConstantsEx.au3>

Global $aItems[4][2] = [["Item 1", "SubItem 1"], ["Item 2", "SubItem 2"], ["Item 3", "SubItem 3"], ["Item 4", "SubItem 4"]]

$hGUI = GUICreate("Test", 500, 500)

$hLV = GUICtrlCreateListView("Col 1     |Col 2", 10, 10, 200, 200)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)

For $i = 0 To UBound($aItems) - 1
    ; Clear the item string
    $sItem = ""
    For $j = 0 To UBound($aItems, 2) - 1
        ; Add each item and subitem to the string
        $sItem &= $aItems[$i][$j] & "|"
    Next
    ; Add the item string
    GUICtrlCreateListViewItem($sItem, $hLV)
    ; Set the alternate line colour
    GUICtrlSetBkColor(-1, 0xCCCCCC)
Next

GUISetState()

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

Any use? :P

M23

I do so then, thank you so much =)
Link to comment
Share on other sites

  • 6 months later...

Hi,

Sorry for bumping this, but does this mean that there's no way to set a line's color after populating the ListView?

I want to set different row color according to certain parameters that I select dynamically in another controls.

I tried

GUICtrlSetBkColor(_GUICtrlListView_GetItemParam($hListView, 3), 0xCCCCCC)

but it would seem that this "GetItemParam" doesn't return a valid handle that I could play with...

footswitch

Link to comment
Share on other sites

  • 3 years later...

4 year bump.....

Just a note on the above post.  I could not figure out for the life of me why I could not make it work, the notes from footswitch would seem to indicate he got it working.

The issue is how the listview is populated.   If you use "_GUICtrlListView_AddArray" to populate your listview the above command does not work.   Instead of sticking the array in there.  Loop though the array and add the lines one at a time via the "GUICtrlCreateListViewItem" command.   This generates controls for each line that can be accessed by the command listed in the above post.

 

In my case, I have a listview that is populated from search results created elsewhere in the script. I want these results presented to the user so they may be picked one a time and worked on.  I want to change the color to show that a line has been done.  In my case I highlight a line.  Press enter,  It gets read, processed elsewhere and comes back to change the color to indicate that the line is been done.  As this is a search result of our customer orders not all lines in the array will be looked at.  And it can be a few min before I come back between each record.  Hence I wanted an easy way to see where I left off when I did come back to it.

 

$c_listview_results   is my listview in my gui.

$a_found_records   is an array of results that I want to display so the user can pick out certain lines.  It has got an unknown number of rows and 6 col.

This.

_GUICtrlListView_AddArray($c_listview_results, $a_found_records)

And this.

    For $i = 0 To UBound($a_found_records)-1 Step 1
        $line = $a_found_records[$i][0] & '|' & $a_found_records[$i][1] & '|' & $a_found_records[$i][2] & '|' & $a_found_records[$i][3] & '|' & $a_found_records[$i][4] & '|' & $a_found_records[$i][5]
        GUICtrlCreateListViewItem($line, $c_listview_results )
    Next

Both populate the listview and look identical.  But only the second bit of code works with the color changing line shown below.

Latter in the script I use the posted line from above to make the change.

GUICtrlSetBkColor(_GUICtrlListView_GetItemParam(GUICtrlGetHandle($c_listview_results), $index), 0x00ff00)

where

$index is the 0 based index of what line was highlighted when I pressed enter.

0x00ff00   is just the color green.

Doing it this way I can generate and display the listview, but only color certain lines as I process them.

 

I'm sure someone will come along and say how to access the controls generated by the arrayadd command but I was not able to figure it out.  This method does work fine for me.

Cal.

 

 

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