Simpel Posted January 7, 2018 Share Posted January 7, 2018 (edited) Hi. I'm trying to split my listview optical only. Rows 1-3 should be normal but all rows after 3 should have a darker background. (Later on these rows are out of scope, so this should be a remark.) You see my $hMark4To6. This should contain the dark color. If I declare $hMark4To6 before the listview I couldn't sort rows 4-6 anymore. But this should work. Is $hMark4To6 below the listview then nothing happens. How can I solve this? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <Misc.au3> Global $hGUI = GUICreate("listview items", 220, 250, 100, 200) Global $g_hListView = GUICtrlCreateListView("col1|col2|col3", 10, 10, 200, 230) For $i = 1 To 6 GUICtrlCreateListViewItem("item" & $i & "|col" & $i & "2|col" & $i & "3", $g_hListView) Next Local $hMark4To6 = GUICtrlCreateLabel("", 10, 90, 200, 150) GUICtrlSetBkColor(-1, 0x888888) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_PRIMARYDOWN _Arrange_List() EndSwitch WEnd Func _Arrange_List() Local $aMouseCoord = MouseGetPos() Local $hListViewHandle = WinGetHandle(ControlGetHandle($hGUI, "", $g_hListView)) Local $aListViewCoord = WinGetPos($hListViewHandle) If $aMouseCoord[0] < $aListViewCoord[0] Then Return ; links von LV If $aMouseCoord[0] > $aListViewCoord[0] + $aListViewCoord[2] Then Return ; rechts von LV If $aMouseCoord[1] < $aListViewCoord[1] + 30 Then Return ; oberhalb von LV (+30 inklusive Überschriftzeile) If $aMouseCoord[1] > $aListViewCoord[1] + $aListViewCoord[3] Then Return ; unterhalb von LV Local $Selected = _GUICtrlListView_GetSelectionMark($g_hListView) If $Selected = -1 Then Return While _IsPressed(1) WEnd Local $Dropped = _GUICtrlListView_GetHotItem($g_hListView) If $Dropped > -1 Then _GUICtrlListView_BeginUpdate($g_hListView) If $Selected < $Dropped Then _GUICtrlListView_InsertItem($g_hListView, "", $Dropped + 1) ; leer einfügen, da der Delimiter nicht funktioniert _GUICtrlListView_SetItemText($g_hListView, $Dropped +1, _GUICtrlListView_GetItemTextString($g_hListView, $Selected), -1) ; nur mit SubItem -1 wird der String mit Delimiter auf das ganze Item angewandt _GUICtrlListView_DeleteItem($g_hListView, $Selected) ElseIf $Selected > $Dropped Then _GUICtrlListView_InsertItem($g_hListView, "", $Dropped) _GUICtrlListView_SetItemText($g_hListView, $Dropped, _GUICtrlListView_GetItemTextString($g_hListView, $Selected + 1), -1) _GUICtrlListView_DeleteItem($g_hListView, $Selected + 1) EndIf _GUICtrlListView_SetItemSelected($g_hListView, $Dropped) _GUICtrlListView_SetSelectionMark($g_hListView, $Dropped) _GUICtrlListView_EndUpdate($g_hListView) EndIf EndFunc Regards, Conrad Edited April 29, 2019 by Simpel [Solved] SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
benners Posted January 8, 2018 Share Posted January 8, 2018 You might be able to accomplish it by using Melba32's UDF here. There are some examples of usage in the zip and GLVEx_Example_6.au3 shows how to colour the cells Link to comment Share on other sites More sharing options...
Skysnake Posted January 17, 2018 Share Posted January 17, 2018 (edited) There are two ways color ListView items.. The standard way is like this: ; color alternate lines of ListView Local LVStdClr = "0xDDEEFF" $ListView = GUICtrlCreateListView("DATE|NAME|BALANCE", 8, 152, 764, 279) GUICtrlSetBkColor($ListView, $GUI_BKCOLOR_LV_ALTERNATE) ; alternate between the listview background color and the listview item background color GUICtrlSetBkColor($ListView, $LVStdClr) ; Set the background color for the listview ;... For ... ; this is the main loop to process and return pretty formatted report GUICtrlSetData($item, $hist) ; set the ListView item values GUICtrlSetBkColor($item, $LVAltClr) Next What you want will require this: ; user defined colors for listview items $ListView = GUICtrlCreateListView("DATE|NAME|BALANCE", 8,152, 763, 279) ;GUICtrlSetBkColor($ListView, $GUI_BKCOLOR_LV_ALTERNATE) ; alternate between the listview background color and the listview item background color ;GUICtrlSetBkColor($ListView, $LVStdClr) ; Set the background color for the listview Local $red = "0xFF0000", $blue = "0x0000FF" ;... ; make pretty report For ... ; outer loop GUICtrlSetData($item, $hist) ; set the ListView values ;GUICtrlSetBkColor($item, $LVAltClr) ; we do not use the auto-coloring For $j = 0 To ($colors) - 1) Step 1 ; nested FOR to color each item If $red = $aResult[$i][1] Then GUICtrlSetBkColor($item, $red ; Set the background color for the listview item If $blue = $aResult[$i][1] Then GUICtrlSetBkColor($item, $blue ; Set the background color for the listview item Next ; end of custom color nested FOR loop Next ; end outer loop The idea is to predefined (a) your list of colors and apply a set color to a specific line - like red = error, yellow = notice, green = good. Then (b) match those colors to the data returned an IF it matches, apply the color. Hope it helps. Edited January 17, 2018 by Skysnake typos Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
Simpel Posted April 29, 2019 Author Share Posted April 29, 2019 Hi, another attempt after solving a problem with _GUICtrlListView_GetItemParam() here (https://www.autoitscript.com/forum/topic/198611-solved-_guictrllistview_setitemparam-doesnt-seem-to-work/?do=findComment&comment=1426250. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <Misc.au3> Local $aArray_Base[5][2] = [["0 - 0", "0 - 1"], ["1 - 0", "1 - 1"], ["2 - 0", "2 - 1"], ["3 - 0", "3 - 1"], ["4 - 0", "4 - 1"]] Global $hGUI = GUICreate("listview items", 220, 200) Global $g_hListView = GUICtrlCreateListView("", 10, 10, 200, 180) _GUICtrlListView_AddColumn($g_hListView, "Col 1", 100) _GUICtrlListView_AddColumn($g_hListView, "Col 2", 100) _GUICtrlListView_AddArray($g_hListView, $aArray_Base) _ChangeColor() GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_PRIMARYDOWN _Arrange_List() EndSwitch WEnd Func _Arrange_List() Local $Selected = _GUICtrlListView_GetSelectionMark($g_hListView) If $Selected = -1 Then Return While _IsPressed(1) WEnd Local $Dropped = _GUICtrlListView_GetHotItem($g_hListView) If $Dropped > -1 Then _GUICtrlListView_BeginUpdate($g_hListView) If $Selected < $Dropped Then _GUICtrlListView_InsertItem($g_hListView, "", $Dropped + 1) _GUICtrlListView_SetItemText($g_hListView, $Dropped +1, _GUICtrlListView_GetItemTextString($g_hListView, $Selected), -1) _GUICtrlListView_DeleteItem($g_hListView, $Selected) ElseIf $Selected > $Dropped Then _GUICtrlListView_InsertItem($g_hListView, "", $Dropped) _GUICtrlListView_SetItemText($g_hListView, $Dropped, _GUICtrlListView_GetItemTextString($g_hListView, $Selected + 1), -1) _GUICtrlListView_DeleteItem($g_hListView, $Selected + 1) EndIf _GUICtrlListView_SetItemSelected($g_hListView, $Dropped) _GUICtrlListView_SetSelectionMark($g_hListView, $Dropped) _GUICtrlListView_EndUpdate($g_hListView) _ChangeColor() EndIf EndFunc Func _ChangeColor() Local $iParam, $iSuccess For $i = 0 To _GUICtrlListView_GetItemCount($g_hListView) - 1 $iParam = 1000 + Int($i) $iSuccess = _GUICtrlListView_SetItemParam($g_hListView, $i, $iParam) If $iSuccess = False Then ConsoleWrite("Error Set: " & $i & @CRLF) ExitLoop EndIf Next Local $iControlID For $i = 0 To _GUICtrlListView_GetItemCount($g_hListView) - 1 $iControlID = _GUICtrlListView_GetItemParam($g_hListView, $i) ConsoleWrite("ControlID: " & $iControlID & @CRLF) If $i > 2 Then $iSuccess = GUICtrlSetBkColor($iControlID, 0xAA0000) ConsoleWrite("Success: " & $iSuccess & @CRLF) $iSuccess = _GUICtrlListView_SetTextBkColor($iControlID, 0xAA0000) ConsoleWrite("Success: " & $iSuccess & @CRLF) EndIf Next EndFunc GUICtrlSetBkColor() returns always 0 and _GUICtrlListView_SetTextBkColor() returns false. Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
BrewManNH Posted April 29, 2019 Share Posted April 29, 2019 Maybe you should stop trying to use it then? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Simpel Posted April 29, 2019 Author Share Posted April 29, 2019 If I read the help file regarding GUICtrlSetBkColor() I can read at remarks "Only Button, Label, Checkbox, Group, Radio, Edit, Input, List, Listview, ListviewItem, Treeview, TreeviewItem, Graphic, Progress, Slider and Combo controls can currently be colored." So it doesn't seem to be the wrong function at all. Why should I stop trying to use it? Better would be to use it in a correct way. GUICtrlSetBkColor() needs the controlID as said in the help file, _GUICtrlListView_SetTextBkColor() needs the coontrolID or the handle. So I think _GUICtrlListView_[Set/Get]ItemParam() won't set/get a controlID or a handle. How can I identify them to set a color? Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
BrewManNH Posted April 29, 2019 Share Posted April 29, 2019 Use the native functions to create the items and then you'll get the control IDs, or you could use the handles returned by the _GUIListview* functions instead of trying to get the control ids. The example scripts for _GUICtrlListView_SetTextBkColor show you how. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Simpel Posted April 29, 2019 Author Share Posted April 29, 2019 Hi, I only found one example script for _GUICtrlListView_SetTextBkColor() in help file. That regards the whole listview not their items. Nevertheless I found another way to color my listviewitems at given row: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <Misc.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Local $aArray_Base[5][2] = [["0 - 0", "0 - 1"], ["1 - 0", "1 - 1"], ["2 - 0", "2 - 1"], ["3 - 0", "3 - 1"], ["4 - 0", "4 - 1"]] Global $hGUI = GUICreate("listview items", 220, 200) Global $g_hListView = GUICtrlCreateListView("", 10, 10, 200, 180) ConsoleWrite("ListView: " & GUICtrlGetHandle($g_hListView) & @CRLF) _GUICtrlListView_AddColumn($g_hListView, "Col 1", 100) _GUICtrlListView_AddColumn($g_hListView, "Col 2", 100) _GUICtrlListView_AddArray($g_hListView, $aArray_Base) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_PRIMARYDOWN _Arrange_List() EndSwitch WEnd Func _Arrange_List() Local $Selected = _GUICtrlListView_GetSelectionMark($g_hListView) If $Selected = -1 Then Return While _IsPressed(1) WEnd Local $Dropped = _GUICtrlListView_GetHotItem($g_hListView) If $Dropped > -1 Then _GUICtrlListView_BeginUpdate($g_hListView) If $Selected < $Dropped Then _GUICtrlListView_InsertItem($g_hListView, "", $Dropped + 1) _GUICtrlListView_SetItemText($g_hListView, $Dropped +1, _GUICtrlListView_GetItemTextString($g_hListView, $Selected), -1) _GUICtrlListView_DeleteItem($g_hListView, $Selected) ElseIf $Selected > $Dropped Then _GUICtrlListView_InsertItem($g_hListView, "", $Dropped) _GUICtrlListView_SetItemText($g_hListView, $Dropped, _GUICtrlListView_GetItemTextString($g_hListView, $Selected + 1), -1) _GUICtrlListView_DeleteItem($g_hListView, $Selected + 1) EndIf _GUICtrlListView_SetItemSelected($g_hListView, $Dropped) _GUICtrlListView_SetSelectionMark($g_hListView, $Dropped) _GUICtrlListView_EndUpdate($g_hListView) EndIf EndFunc Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tNMHDR, $code, $hwndFrom, $tDraw, $dwDrawStage, $dwItemSpec $tNMHDR = DllStructCreate($tagNMHDR, $lParam) ;NMHDR (hwndFrom, idFrom, code) If @error Then Return $code = DllStructGetData($tNMHDR, "Code") $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom") Switch $hwndFrom Case GUICtrlGetHandle($g_hListView) Switch $code Case $NM_CUSTOMDRAW $tDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) $dwDrawStage = DllStructGetData($tDraw, "dwDrawStage") $dwItemSpec = DllStructGetData($tDraw, "dwItemSpec") Switch $dwDrawStage Case $CDDS_ITEMPREPAINT If $dwItemSpec > 2 Then DllStructSetData($tDraw, "clrTextBk", 0x00FF00) EndIf EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY That script (https://www.autoitscript.com/forum/topic/58714-drag-and-drop-within-listview/?do=findComment&comment=443841) by @GaryFrost linked me to the right direction. Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 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