darkshark Posted January 8, 2011 Share Posted January 8, 2011 (edited) 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 January 8, 2011 by darkshark Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 8, 2011 Moderators Share Posted January 8, 2011 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: #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? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
darkshark Posted January 8, 2011 Author Share Posted January 8, 2011 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: #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? M23 I do so then, thank you so much =) Link to comment Share on other sites More sharing options...
footswitch Posted July 12, 2011 Share Posted July 12, 2011 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 More sharing options...
footswitch Posted July 12, 2011 Share Posted July 12, 2011 Forget about that, found it GUICtrlSetBkColor(_GUICtrlListView_GetItemParam(GUICtrlGetHandle($hListView), 3), 0xCCCCCC) GetItemParam needs the control handle, not the control ID. Link to comment Share on other sites More sharing options...
cal Posted February 24, 2015 Share Posted February 24, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now