faustf Posted July 29, 2018 Posted July 29, 2018 hi guys , i try to colored a one row insiede at listview (example i want color all row in green ), is possible to do that ? , i have a script like this expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> #include <File.au3> Opt("GuiOnEventMode", 1) Opt("GUICloseOnESC", 0) Opt("GUIResizeMode", 128) _gui() Func _gui() $Form3 = GUICreate("Form3", 1246, 517, 302, 218) Global $SITIWEB_Prod_in_vendita_list = _ListView_OK("", 8, 86, 1675, 274, "Item ID_150_Nome Prodotto_360_Qt._50_Formato_100_Prezzo C.S._100_Prezzo Asta_100_Prezzo Spedizione_100_Proposta d'acquisto_100_Data Apertura_100_Tempo Chiusura_100_Url Site_350") GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, _close) _populate() EndFunc ;==>_gui Func _populate() _GUICtrlListView_AddItem($SITIWEB_Prod_in_vendita_list, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($SITIWEB_Prod_in_vendita_list, 0, "Row 1: Col 2", 1, 1) _GUICtrlListView_AddSubItem($SITIWEB_Prod_in_vendita_list, 0, "Row 1: Col 3", 2, 2) _GUICtrlListView_AddItem($SITIWEB_Prod_in_vendita_list, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($SITIWEB_Prod_in_vendita_list, 1, "Row 2: Col 2", 1, 2) _GUICtrlListView_AddItem($SITIWEB_Prod_in_vendita_list, "Row 3: Col 1", 2) EndFunc ;==>_populate Func _ListView_OK($text, $left, $top, $width, $height, $Column, $SingleSEL = "") If $SingleSEL = "" Then Global $vGName = GUICtrlCreateListView($text, $left, $top, $width, $height, BitOR($LVS_EDITLABELS, $LVS_REPORT)) Else Global $vGName = GUICtrlCreateListView($text, $left, $top, $width, $height, BitOR($LVS_EDITLABELS, $LVS_REPORT, $LVS_SINGLESEL)) EndIf _GUICtrlListView_SetExtendedListViewStyle($vGName, BitOR($LVS_EX_INFOTIP, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES, $LVS_EX_HEADERDRAGDROP)) ; questa stringa fa la griglia stile excel Local $aColumn = StringSplit($Column, "_") For $i = 1 To UBound($aColumn) - 1 _GUICtrlListView_AddColumn($vGName, $aColumn[$i], $aColumn[($i + 1)]) ; Utente fake $i += 1 Next Return $vGName EndFunc ;==>_ListView_OK While 1 Sleep(100) WEnd Func _close() Exit EndFunc ;==>_close i tryed to follow but the example of Zedna is for intercept click and i dont know how modify for create a line colored anyone can help me ? thankz
AutoBert Posted July 29, 2018 Posted July 29, 2018 Here a small demoscript of mine: expandcollapse popup;https://autoit.de/index.php/Thread/84194-Alternativer-L%C3%B6sungsweg-GuiCtrlSetBkColor/?postID=673544#post673544 #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <ListviewConstants.au3> #include <array.au3> #include <File.au3> Global $aNames[1] _FileReadToArray('Benutzer.txt', $aNames, $FRTA_NOCOUNT) $hGui = GUICreate("LV-Items färben", 220, 400) $listview = GUICtrlCreateListView("Name|Status|CtrlID", 10, 10, 210, 350, $LVS_REPORT) For $i = 0 To UBound($aNames) - 1 $iItem = GUICtrlCreateListViewItem($aNames[$i] & "|Offline", $listview) GUICtrlSetData($iItem, "||" & $iItem) Next $idAdd = GUICtrlCreateButton('+', 10, 370, 30) $idDel = GUICtrlCreateButton('-', 180, 370, 30) _GUICtrlListView_SetColumnWidth($listview, 0, 140) _GUICtrlListView_SetColumnWidth($listview, 1, 40) ;_GUICtrlListView_SetColumnWidth($listview, 2, 0) ;0 = unsichtbar _GUICtrlListView_RegisterSortCallBack($listview) _RandomOnOff() GUISetState(@SW_SHOW) ;GUICtrlSetColor(-1, 0x22C21F) ;GUICtrlSetColor(-1, 0xAA0000) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE _GUICtrlListView_UnRegisterSortCallBack($listview) _FileWriteFromArray('Benutzer.txt', $aNames) Exit Case $listview _GUICtrlListView_SortItems($listview, GUICtrlGetState($listview)) Case $idDel AdlibUnRegister("_RandomOnOff") ;damit sich die Indizes nicht durch Neu-Sortierung ändern $aSelected = _GUICtrlListView_GetSelectedIndices($listview, True) If IsArray($aSelected) Then For $i = 1 To $aSelected[0] $aItem = _GUICtrlListView_GetItemTextArray($listview, $aSelected[$i]) If MsgBox($MB_YESNO + $MB_ICONQUESTION + $MB_DEFBUTTON2, $aItem[1], 'Soll Eintrag gelöscht werden?', $hGui) = $idYes Then GUICtrlDelete($aItem[3]) $iItem = _ArraySearch($aNames, $aItem[1]) _ArrayDelete($aNames, $iItem) EndIf Next EndIf AdlibRegister("_RandomOnOff", Random(5000, 10000, 1)) Case $idAdd $sText = InputBox('Neuer Benutzer', 'Benutzer', Default, '', 20) If MsgBox($MB_YESNO + $MB_ICONQUESTION + $MB_DEFBUTTON1, $sText, 'Soll Eintrag hinzugefügt werden?', $hGui) = $idYes Then $iItem = GUICtrlCreateListViewItem($sText & "|Neu", $listview) _ArrayAdd($aNames, $sText) GUICtrlSetData($iItem, "||" & $iItem) _GUICtrlListView_EnsureVisible($listview, UBound($aNames) - 1) GUICtrlSetBkColor($iItem, 0x00FF12) Sleep(2000) EndIf EndSwitch WEnd Func _RandomOnOff() AdlibUnRegister("_RandomOnOff") _GUICtrlListView_BeginUpdate($listview) For $i = 0 To _GUICtrlListView_GetItemCount($listview) - 1 $aItem = _GUICtrlListView_GetItemTextArray($listview, $i) ;_ArrayDisplay($aItem) If IsArray($aItem) Then If Random(1, 3, 1) = 1 Then GUICtrlSetData($aItem[3], "|Off") GUICtrlSetBkColor($aItem[3], 0xAA0000) Else GUICtrlSetData($aItem[3], "|On") GUICtrlSetBkColor($aItem[3], 0x22C21F) EndIf EndIf Next If GUICtrlGetState($listview) = 1 Then _GUICtrlListView_SortItems($listview, 0) _GUICtrlListView_SortItems($listview, 1) EndIf _GUICtrlListView_EndUpdate($listview) AdlibRegister("_RandomOnOff", Random(5000, 10000, 1)) EndFunc ;==>_RandomOnOff need's Benutzer.txt See also example 2 in helpfile GUICtrlSetBkColor
faustf Posted July 30, 2018 Author Posted July 30, 2018 question about your script , i notice you use this instruction for take different controlid for row , i try to do the same with my script $iItem = GUICtrlCreateListViewItem($sText & "|Neu", $listview) this is my script modify expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> #include <File.au3> Opt("GuiOnEventMode", 1) Opt("GUICloseOnESC", 0) Opt("GUIResizeMode", 128) _gui() Func _gui() $Form3 = GUICreate("Form3", 1246, 517, 302, 218) Global $SITIWEB_Prod_in_vendita_list = _ListView_OK("", 8, 86, 1675, 274, "Item ID_150_Nome Prodotto_360_Qt._50_Formato_100_Prezzo C.S._100_Prezzo Asta_100_Prezzo Spedizione_100_Proposta d'acquisto_100_Data Apertura_100_Tempo Chiusura_100_Url Site_350") GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, _close) _populate() EndFunc ;==>_gui Func _populate() _GUICtrlListView_AddItem($SITIWEB_Prod_in_vendita_list, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($SITIWEB_Prod_in_vendita_list, 0, $SITIWEB_Prod_in_vendita_list, 1, 1) _GUICtrlListView_AddSubItem($SITIWEB_Prod_in_vendita_list, 0, "Row 1: Col 3", 2, 2) _GUICtrlListView_AddItem($SITIWEB_Prod_in_vendita_list,$SITIWEB_Prod_in_vendita_list, 1) _GUICtrlListView_AddSubItem($SITIWEB_Prod_in_vendita_list, 1, "Row 2: Col 2", 1, 2) _GUICtrlListView_AddItem($SITIWEB_Prod_in_vendita_list, "Row 3: Col 1", 2) _GUICtrlListView_BeginUpdate($SITIWEB_Prod_in_vendita_list) ;Local $aItem = _GUICtrlListView_GetItemTextArray($SITIWEB_Prod_in_vendita_list, 1) ;_ArrayDisplay($aItem,'8004') GUICtrlSetBkColor(3, 0xCCFFCC) _GUICtrlListView_EndUpdate($SITIWEB_Prod_in_vendita_list) EndFunc ;==>_populate Func _ListView_OK($text, $left, $top, $width, $height, $Column, $SingleSEL = "") If $SingleSEL = "" Then Global $vGName = GUICtrlCreateListView($text, $left, $top, $width, $height, BitOR($LVS_EDITLABELS, $LVS_REPORT)) Else Global $vGName = GUICtrlCreateListView($text, $left, $top, $width, $height, BitOR($LVS_EDITLABELS, $LVS_REPORT, $LVS_SINGLESEL)) EndIf _GUICtrlListView_SetExtendedListViewStyle($vGName, BitOR($LVS_EX_INFOTIP, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES, $LVS_EX_HEADERDRAGDROP)) ; questa stringa fa la griglia stile excel Local $aColumn = StringSplit($Column, "_") For $i = 1 To UBound($aColumn) - 1 _GUICtrlListView_AddColumn($vGName, $aColumn[$i], $aColumn[($i + 1)]) ; Utente fake $i += 1 Next Return $vGName EndFunc ;==>_ListView_OK While 1 Sleep(100) WEnd Func _close() Exit EndFunc ;==>_close but why my listview remaning always at 3 ???
AutoBert Posted July 30, 2018 Posted July 30, 2018 GUICtrlSetBkColor works only with the controlid (as returned from native GUICtrlCreateListViewItem) not with the handle (as returned from the funcs, you are using) . So i suggest create your listview and the items with the native func's.
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