Simpel Posted April 17, 2019 Share Posted April 17, 2019 (edited) Hi, I make a listview. Later I want to re-arrange the listviewitems and change at some point the backcolor. Therefor I want to set them a new controlid. This is the code to show, what is not working: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> Example() Func Example() GUICreate("listview items", 222, 190) Local $idListview = GUICtrlCreateListView("col1|col2|col3", 10, 10, 202, 170) Local $iSuccess For $i = 0 To 4 $iSuccess = GUICtrlCreateListViewItem($i & "|" & $i & "|" & $i, $idListview) ConsoleWrite("Create: " & $iSuccess & @CRLF) If $i > 1 Then $iSuccess = GUICtrlSetBkColor($iSuccess, 0x00AA00) ConsoleWrite("Success: " & $iSuccess & @CRLF) EndIf Next GUISetState(@SW_SHOW) Sleep(2000) ; later a lot of code for re-arrange listviewitems w/ drag&drop ; #cs ; comment out this to see, that it works w/o setting a new controlid Local $iParam For $i = 0 To _GUICtrlListView_GetItemCount($idListview) - 1 $iParam = 1000 + Int($i) $iSuccess = _GUICtrlListView_SetItemParam($idListview, $i, $iParam) If $iSuccess = False Then ConsoleWrite("$i: " & $i & @CRLF) ExitLoop EndIf Next ; #ce ; comment out until here Local $iControlID For $i = 0 To _GUICtrlListView_GetItemCount($idListview) - 1 $iControlID = _GUICtrlListView_GetItemParam($idListview, $i) ConsoleWrite("ControlID: " & $iControlID & @CRLF) If $i > 2 Then $iSuccess = GUICtrlSetBkColor($iControlID, 0xAA0000) ConsoleWrite("Success: " & $iSuccess & @CRLF) EndIf Next ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc ;==>Example Any ideas? Regards, Simpel 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...
Simpel Posted April 29, 2019 Author Share Posted April 29, 2019 Maybe I found a hint? This is a little snippet to show some problem: expandcollapse popupGlobal $hGUI = GUICreate("listview items", 220, 200) Global $g_hListView = GUICtrlCreateListView("col1|col2|col3", 10, 10, 200, 180) For $i = 1 To 6 GUICtrlCreateListViewItem("item" & $i & "|col" & $i & "2|col" & $i & "3", $g_hListView) Next _GetIDs() 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) _GetIDs() EndIf EndFunc Func _GetIDs() Local $iControlID For $i = 0 To _GUICtrlListView_GetItemCount($g_hListView) - 1 $iControlID = _GUICtrlListView_GetItemParam($g_hListView, $i) ConsoleWrite("ControlID: " & $iControlID & @CRLF) Next ConsoleWrite(@CRLF) EndFunc The controlIDs written at console will be 4 to 9 at start. When I drag one row then this row will have the return value 0. All others keep their value. What is happening there? 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...
Simpel Posted April 29, 2019 Author Share Posted April 29, 2019 Ok, it's written on the help file, but not the proper place. If you look at _GUICtrlListView_GetItemParam() you will find in the example a comment: ; Warning do not use SetItemParam on items created with GUICtrlCreateListViewItem I would expect that at _GUICtrlListView_SetItemParam() inside the remarks. It could look like this: 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) Next EndFunc But at least that is not solving my problem here: https://www.autoitscript.com/forum/topic/191829-listview-lower-part-should-be-colored/ 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