trn80 Posted December 5, 2019 Share Posted December 5, 2019 Hi all, I am trying to create a GUIListViewEx where rows color are different based to the value of the listView column, but i can't understand how to achieve it. The data to display comes from a database so I don't know how to create the colorsArray to pass in the _GUIListViewEx_LoadColour function. If the c5 column values 1 the row must be green, else must be red, could you please help me? Thank you in advance! expandcollapse popup#include <SQLite.dll.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> #include <StaticConstants.au3> #include <UpDownConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <Misc.au3> #include <String.au3> #include <Array.au3> #include <GUIListViewEx.au3> Global $iGreen = "0x00FF00", _ $iBlack = "0x000000", _ $iRed = "0xFF0000", _ $iWhite = "0xFFFFFF" Global $sRet ; Create GUI $hGUI = GUICreate("My GUI", 700, 230, -1, -1, BitOR($WS_SIZEBOX, $WS_SYSMENU)) ; Create ListView For represent a db table with 6 column $idListview = GUICtrlCreateListView("C0|C1|C2|C3|C4|C5", 5, 5, 610, 180, BitOr($LVS_REPORT, $LVS_SHOWSELALWAYS, $WS_BORDER)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP)) Global $dataPoolArray = retrieveData() ; THE DATAPOOL SIZE IS UNKNOWN A THIS POINT, IT COMES FROM DATABASE _GUICtrlListView_AddArray($idListview, $dataPoolArray) ; Initiate ListView = sort on column click - editable headers - header colours - user colours $iLVIndex_1 = _GUIListViewEx_Init($idListview, $dataPoolArray, 0, 0, True, 1 + 8 + 32) ; + 16 ; **** IF the last column of the row is '1' the background color must be $iGreen, else must be $iRed **** Local $dataPoolRowNum = UBound($dataPoolArray, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10. Local $dataPoolColNum = UBound($dataPoolArray, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20. ;~ ???? Global $aLVCol_1 = ????? ;~ ???? _GUIListViewEx_LoadColour($iLVIndex_1, ????? ) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ConsoleWrite("Ricevuto evento EXIT" & @CRLF) Exit EndSwitch WEnd Func retrieveData() Local $array [2][6] = [['v00','v01','v02','v03','v04','1'],['v10','v11','v12','v13','v14','0']] return $array EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 5, 2019 Moderators Share Posted December 5, 2019 trn80, Welcome to the AutoIt forums. You can do it like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListViewEx.au3> Global $iGreen = "0x00FF00", $iRed = "0xFF0000" Global $sRet ; Create GUI $hGUI = GUICreate("My GUI", 700, 230, -1, -1, BitOR($WS_SIZEBOX, $WS_SYSMENU)) ; Create ListView For represent a db table with 6 column $idListview = GUICtrlCreateListView("C0|C1|C2|C3|C4|C5", 5, 5, 610, 180, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $WS_BORDER)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP)) Global $dataPoolArray = retrieveData() ; THE DATAPOOL SIZE IS UNKNOWN A THIS POINT, IT COMES FROM DATABASE _GUICtrlListView_AddArray($idListview, $dataPoolArray) ; Initiate ListView = sort on column click - editable headers - header colours - user colours $iLVIndex_1 = _GUIListViewEx_Init($idListview, $dataPoolArray, 0, 0, True, 1 + 8 + 32) ; + 16 ; **** IF the last column of the row is '1' the background color must be $iGreen, else must be $iRed **** Local $dataPoolRowNum = UBound($dataPoolArray, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10. Local $dataPoolColNum = UBound($dataPoolArray, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20. ; Create colour array - 0-based to fit ListView content Global $aLVCol_1[$dataPoolRowNum][$dataPoolColNum] For $iRow = 0 To $dataPoolRowNum - 1 If $dataPoolArray[$iRow][5] = 1 Then ; Check the required column and fill colour array accordingly For $iCol = 0 To $dataPoolColNum - 1 $aLVCol_1[$iRow][$iCol] = ";" & $iGreen Next Else For $iCol = 0 To $dataPoolColNum - 1 $aLVCol_1[$iRow][$iCol] = ";" & $iRed Next EndIf Next ; Load colour array into ListView _GUIListViewEx_LoadColour($iLVIndex_1, $aLVCol_1) ; If colours used then this function must be run BEFORE GUISetState _GUIListViewEx_MsgRegister() GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ConsoleWrite("Ricevuto evento EXIT" & @CRLF) Exit EndSwitch WEnd Func retrieveData() Local $array[2][6] = [['v00', 'v01', 'v02', 'v03', 'v04', '1'], ['v10', 'v11', 'v12', 'v13', 'v14', '0']] Return $array EndFunc ;==>retrieveData I hope that is clear - please ask again if not. And in future if you have questions about any of my UDFs please post in the relevant thread as it flags it to me immediately. 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...
trn80 Posted December 5, 2019 Author Share Posted December 5, 2019 It works perfectly! Thank you very much. I've another question about GUIListViewEx, I will post it in your thread Thank you! 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