MrCreatoR Posted January 17, 2008 Posted January 17, 2008 expandcollapse popup;=============================================================================== ; Function Name: _GUICtrlListView_MoveItems() ; Description: Move selected item(s) in ListView Up or Down. ; ; Parameter(s): $hWnd - Window handle of ListView control (can be a Title). ; $vListView - The ID/Handle/Class of ListView control. ; $iDirection - [Optional], define in what direction item(s) will move: ; 1 (default) - item(s) will move Next. ; -1 item(s) will move Back. ; $sIconsFile - Icon file to set image for the items (only for internal usage). ; $iIconID_Checked - Icon ID in $sIconsFile for checked item(s). ; $iIconID_UnChecked - Icon ID in $sIconsFile for Unchecked item(s). ; ; Requirement(s): #include <GuiListView.au3>, AutoIt 3.2.10.0. ; ; Return Value(s): On seccess - Move selected item(s) Next/Back. ; On failure - Return "" (empty string) and set @error as following: ; 1 - No selected item(s). ; 2 - $iDirection is wrong value (not 1 and not -1). ; 3 - Item(s) can not be moved, reached last/first item. ; ; Note(s): * This function work with external ListView Control as well. ; * If you select like 15-20 (or more) items, moving them can take a while :( (depends on how many items moved). ; ; Author(s): G.Sandler a.k.a CreatoR (http://creator-lab.ucoz.ru) ;=============================================================================== Func _GUICtrlListView_MoveItems($hWnd, $vListView, $iDirection=1, $sIconsFile="", $iIconID_Checked=0, $iIconID_UnChecked=0) Local $hListView = $vListView If Not IsHWnd($hListView) Then $hListView = ControlGetHandle($hWnd, "", $hListView) Local $aSelected_Indices = _GUICtrlListView_GetSelectedIndices($hListView, 1) If UBound($aSelected_Indices) < 2 Then Return SetError(1, 0, "") If $iDirection <> 1 And $iDirection <> -1 Then Return SetError(2, 0, "") Local $iTotal_Items = ControlListView($hWnd, "", $hListView, "GetItemCount") Local $iTotal_Columns = ControlListView($hWnd, "", $hListView, "GetSubItemCount") Local $iUbound = UBound($aSelected_Indices)-1, $iNum = 1, $iStep = 1 Local $iCurrent_Index, $iUpDown_Index, $sCurrent_ItemText, $sUpDown_ItemText Local $iCurrent_Index, $iCurrent_CheckedState, $iUpDown_CheckedState If ($iDirection = -1 And $aSelected_Indices[1] = 0) Or _ ($iDirection = 1 And $aSelected_Indices[$iUbound] = $iTotal_Items-1) Then Return SetError(3, 0, "") ControlListView($hWnd, "", $hListView, "SelectClear") Local $aOldSelected_IDs[1] Local $iIconsFileExists = FileExists($sIconsFile) If $iIconsFileExists Then For $i = 1 To $iUbound ReDim $aOldSelected_IDs[UBound($aOldSelected_IDs)+1] _GUICtrlListView_SetItemSelected($hListView, $aSelected_Indices[$i], True) $aOldSelected_IDs[$i] = GUICtrlRead($vListView) _GUICtrlListView_SetItemSelected($hListView, $aSelected_Indices[$i], False) Next ControlListView($hWnd, "", $hListView, "SelectClear") EndIf If $iDirection = 1 Then $iNum = $iUbound $iUbound = 1 $iStep = -1 EndIf For $i = $iNum To $iUbound Step $iStep $iCurrent_Index = $aSelected_Indices[$i] $iUpDown_Index = $aSelected_Indices[$i]+1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1 $iCurrent_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iCurrent_Index) $iUpDown_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iUpDown_Index) _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) For $j = 0 To $iTotal_Columns-1 $sCurrent_ItemText = _GUICtrlListView_GetItemText($hListView, $iCurrent_Index, $j) $sUpDown_ItemText = _GUICtrlListView_GetItemText($hListView, $iUpDown_Index, $j) _GUICtrlListView_SetItemText($hListView, $iUpDown_Index, $sCurrent_ItemText, $j) _GUICtrlListView_SetItemText($hListView, $iCurrent_Index, $sUpDown_ItemText, $j) Next _GUICtrlListView_SetItemChecked($hListView, $iUpDown_Index, $iCurrent_CheckedState) _GUICtrlListView_SetItemChecked($hListView, $iCurrent_Index, $iUpDown_CheckedState) If $iIconsFileExists Then If $iCurrent_CheckedState = 1 Then GUICtrlSetImage(GUICtrlRead($vListView), $sIconsFile, $iIconID_Checked, 0) Else GUICtrlSetImage(GUICtrlRead($vListView), $sIconsFile, $iIconID_UnChecked, 0) EndIf If $iUpDown_CheckedState = 1 Then GUICtrlSetImage($aOldSelected_IDs[$i], $sIconsFile, $iIconID_Checked, 0) Else GUICtrlSetImage($aOldSelected_IDs[$i], $sIconsFile, $iIconID_UnChecked, 0) EndIf EndIf _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index, 0) Next For $i = 1 To UBound($aSelected_Indices)-1 $iUpDown_Index = $aSelected_Indices[$i]+1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1 _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) Next EndFunc  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team
Siao Posted January 17, 2008 Posted January 17, 2008 (edited) Not sure what's the purpose of $sIconsFile and other 2 parameters that follow it, but your func doesn't support images (text and checkbox state moves, image stays the same). Easy to fix using _GUICtrlListView_GetItemImage & _GUICtrlListView_SetItemImage. And maybe also _GUICtrlListView_GetItemStateImage & _GUICtrlListView_SetItemStateImage too, just because we can. Just be sure to check for the presence of corresponding ImageLists with _GUICtrlListView_GetImageList. Edited January 17, 2008 by Siao "be smart, drink your wine"
MrCreatoR Posted January 17, 2008 Author Posted January 17, 2008 Hi,Not sure what's the purpose of $sIconsFile and other 2 parameters that follow it, but your func doesn't support imagesIt does support, but just images direct from file, in the old way - GUICtrlSetImage still work i think You just set image file for items, and the index icon in that file for checked/unchecked items.I thought that this func needs modification for the _GUICtrlListView_GetItemImage, but i wrote it a long time ago, and i still not worked with imges format (as in new version) for the ListView. So i will try to modify it later, thanks.  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team
MrCreatoR Posted May 8, 2009 Author Posted May 8, 2009 Ok, here is another version wich preserves the checkbox states and images list of the items: expandcollapse popup;Demo for _GUICtrlListView_MoveItems() function. ;Just select one (or more) item, and press one of the buttons (Up or Down). #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <SendMessage.au3> ; $GUI = GUICreate('Demo for _GUICtrlListView_MoveItems()', 300, 320) $Up_Button = GUICtrlCreateButton("Up", 20, 20, 24, 24, $BS_ICON) GUICtrlSetImage(-1, "netcfgx.dll", 1, 0) $Down_Button = GUICtrlCreateButton("Down", 70, 20, 24, 24, $BS_ICON) GUICtrlSetImage(-1, "netcfgx.dll", -2, 0) $ListView = _GUICtrlListView_Create($GUI, "Column1|Column2", 20, 50, 260, 250, _ BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), $WS_EX_CLIENTEDGE) _GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) $iImage_Size = 14 $hImage = _GUIImageList_Create($iImage_Size, $iImage_Size) _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap($ListView, 0xFF0000, $iImage_Size, $iImage_Size)) _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap($ListView, 0x00FF00, $iImage_Size, $iImage_Size)) _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap($ListView, 0x0000FF, $iImage_Size, $iImage_Size)) _GUICtrlListView_SetImageList($ListView, $hImage, 1) For $i = 0 To 9 _GUICtrlListView_AddItem($ListView, "Item " & $i+1, Random(0, 2, 1)) _GUICtrlListView_AddSubItem($ListView, $i, "SubItem " & $i+1, 1, Random(0, 2, 1)) Next $iRandom_1 = Random(0, 9, 1) $iRandom_2 = Random(0, 9, 1) _GUICtrlListView_SetItemChecked($ListView, $iRandom_1, 1) _GUICtrlListView_SetItemSelected($ListView, $iRandom_1, 1) _GUICtrlListView_SetItemChecked($ListView, $iRandom_2, 1) _GUICtrlListView_SetItemSelected($ListView, $iRandom_2, 1) _SendMessage($ListView, $LVM_SETCOLUMNWIDTH, 0, -1) _SendMessage($ListView, $LVM_SETCOLUMNWIDTH, 1, -1) ControlFocus($GUI, "", $ListView) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Up_Button _GUICtrlListView_MoveItems($ListView, -1) ControlFocus($GUI, "", $ListView) Case $Down_Button _GUICtrlListView_MoveItems($ListView, 1) ControlFocus($GUI, "", $ListView) EndSwitch WEnd ;=============================================================================== ; Function Name: _GUICtrlListView_MoveItems() ; Description: Moves Up or Down selected item(s) in ListView. ; ; Parameter(s): $hListView - ControlID or Handle of ListView control. ; $iDirection - Define in what direction item(s) will move: ; -1 - Move Up. ; 1 - Move Down. ; ; Requirement(s): AutoIt 3.3.0.0 ; ; Return Value(s): On seccess - Move selected item(s) Up/Down and return 1. ; On failure - Return "" (empty string) and set @error as following: ; 1 - No selected item(s). ; 2 - $iDirection is wrong value (not 1 and not -1). ; 3 - Item(s) can not be moved, reached last/first item. ; ; Note(s): * If you select like 15-20 (or more) items, moving them can take a while :( (second or two). ; ; Author(s): G.Sandler a.k.a CreatoR ;=============================================================================== Func _GUICtrlListView_MoveItems($hListView, $iDirection) Local $aSelected_Indices = _GUICtrlListView_GetSelectedIndices($hListView, 1) If UBound($aSelected_Indices) < 2 Then Return SetError(1, 0, "") If $iDirection <> 1 And $iDirection <> -1 Then Return SetError(2, 0, "") Local $iTotal_Items = _GUICtrlListView_GetItemCount($hListView) Local $iTotal_Columns = _GUICtrlListView_GetColumnCount($hListView) Local $iUbound = UBound($aSelected_Indices)-1, $iNum = 1, $iStep = 1 Local $iCurrent_Index, $iUpDown_Index, $sCurrent_ItemText, $sUpDown_ItemText Local $iCurrent_Index, $iCurrent_CheckedState, $iUpDown_CheckedState Local $iImage_Current_Index, $iImage_UpDown_Index If ($iDirection = -1 And $aSelected_Indices[1] = 0) Or _ ($iDirection = 1 And $aSelected_Indices[$iUbound] = $iTotal_Items-1) Then Return SetError(3, 0, "") ControlListView($hListView, "", "", "SelectClear") If $iDirection = 1 Then $iNum = $iUbound $iUbound = 1 $iStep = -1 EndIf For $i = $iNum To $iUbound Step $iStep $iCurrent_Index = $aSelected_Indices[$i] $iUpDown_Index = $aSelected_Indices[$i]+1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1 $iCurrent_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iCurrent_Index) $iUpDown_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iUpDown_Index) _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) For $j = 0 To $iTotal_Columns-1 $sCurrent_ItemText = _GUICtrlListView_GetItemText($hListView, $iCurrent_Index, $j) $sUpDown_ItemText = _GUICtrlListView_GetItemText($hListView, $iUpDown_Index, $j) If _GUICtrlListView_GetImageList($hListView, 1) <> 0 Then $iImage_Current_Index = _GUICtrlListView_GetItemImage($hListView, $iCurrent_Index, $j) $iImage_UpDown_Index = _GUICtrlListView_GetItemImage($hListView, $iUpDown_Index, $j) _GUICtrlListView_SetItemImage($hListView, $iCurrent_Index, $iImage_UpDown_Index, $j) _GUICtrlListView_SetItemImage($hListView, $iUpDown_Index, $iImage_Current_Index, $j) EndIf _GUICtrlListView_SetItemText($hListView, $iUpDown_Index, $sCurrent_ItemText, $j) _GUICtrlListView_SetItemText($hListView, $iCurrent_Index, $sUpDown_ItemText, $j) Next _GUICtrlListView_SetItemChecked($hListView, $iUpDown_Index, $iCurrent_CheckedState) _GUICtrlListView_SetItemChecked($hListView, $iCurrent_Index, $iUpDown_CheckedState) _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index, 0) Next For $i = 1 To UBound($aSelected_Indices)-1 $iUpDown_Index = $aSelected_Indices[$i]+1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1 _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) Next Return 1 EndFunc yutijang 1  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team
yehia Posted May 8, 2009 Posted May 8, 2009 (edited) sry didnt have time to look on the code but can this func manipulate external script's LV? Edit: i mean when the script deals with the LV items with index not text so it works without destroying the LV function Edited May 8, 2009 by yehia My Scripts:IE New UDFsElastic images moving under mouse (with a happy valentine's example)_FileRemoveLine
MrCreatoR Posted May 8, 2009 Author Posted May 8, 2009 (edited) can this func manipulate external script's LV?Yes: expandcollapse popup;Demo for _GUICtrlListView_MoveItems() function. ;Just select one (or more) item, and press one of the buttons (Up or Down). #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <SendMessage.au3> ; _External_GUI() $GUI = GUICreate('Demo for _GUICtrlListView_MoveItems()', 300, 320, 200) $Up_Button = GUICtrlCreateButton("Up", 20, 20, 24, 24, $BS_ICON) GUICtrlSetImage(-1, "netcfgx.dll", 1, 0) $Down_Button = GUICtrlCreateButton("Down", 70, 20, 24, 24, $BS_ICON) GUICtrlSetImage(-1, "netcfgx.dll", -2, 0) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Up_Button, $Down_Button $hListView = ControlGetHandle("_GUICtrlListView_MoveItems- External Test", "", "SysListView321") $iMoveMode = -1 If $nMsg = $Down_Button Then $iMoveMode = 1 _GUICtrlListView_MoveItems($hListView, $iMoveMode) ControlFocus("", "", $hListView) EndSwitch WEnd Func _External_GUI() Local $hGUI, $hListView, $hImageList, $iImage_Size = 14, $iRandom_1, $iRandom_2 $hGUI = GUICreate('_GUICtrlListView_MoveItems- External Test', 300, 320, 520, -1, -1, $WS_EX_TOPMOST) $hListView = _GUICtrlListView_Create($hGUI, "Column1|Column2", 20, 50, 260, 250, _ BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), $WS_EX_CLIENTEDGE) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) $hImageList = _GUIImageList_Create($iImage_Size, $iImage_Size) _GUIImageList_Add($hImageList, _WinAPI_CreateSolidBitmap($hListView, 0xFF0000, $iImage_Size, $iImage_Size)) _GUIImageList_Add($hImageList, _WinAPI_CreateSolidBitmap($hListView, 0x00FF00, $iImage_Size, $iImage_Size)) _GUIImageList_Add($hImageList, _WinAPI_CreateSolidBitmap($hListView, 0x0000FF, $iImage_Size, $iImage_Size)) _GUICtrlListView_SetImageList($hListView, $hImageList, 1) For $i = 0 To 9 _GUICtrlListView_AddItem($hListView, "Item " & $i+1, Random(0, 2, 1)) _GUICtrlListView_AddSubItem($hListView, $i, "SubItem " & $i+1, 1, Random(0, 2, 1)) Next $iRandom_1 = Random(0, 9, 1) $iRandom_2 = Random(0, 9, 1) _GUICtrlListView_SetItemChecked($hListView, $iRandom_1, 1) _GUICtrlListView_SetItemSelected($hListView, $iRandom_1, 1) _GUICtrlListView_SetItemChecked($hListView, $iRandom_2, 1) _GUICtrlListView_SetItemSelected($hListView, $iRandom_2, 1) _SendMessage($hListView, $LVM_SETCOLUMNWIDTH, 0, -1) _SendMessage($hListView, $LVM_SETCOLUMNWIDTH, 1, -1) ControlFocus($hGUI, "", $hListView) GUISetState() EndFunc ;=============================================================================== ; Function Name: _GUICtrlListView_MoveItems() ; Description: Moves Up or Down selected item(s) in ListView. ; ; Parameter(s): $hListView - ControlID or Handle of ListView control. ; $iDirection - Define in what direction item(s) will move: ; -1 - Move Up. ; 1 - Move Down. ; ; Requirement(s): AutoIt 3.3.0.0 ; ; Return Value(s): On seccess - Move selected item(s) Up/Down and return 1. ; On failure - Return "" (empty string) and set @error as following: ; 1 - No selected item(s). ; 2 - $iDirection is wrong value (not 1 and not -1). ; 3 - Item(s) can not be moved, reached last/first item. ; ; Note(s): * If you select like 15-20 (or more) items, moving them can take a while (second or two). ; ; Author(s): G.Sandler a.k.a CreatoR ;=============================================================================== Func _GUICtrlListView_MoveItems($hListView, $iDirection) Local $aSelected_Indices = _GUICtrlListView_GetSelectedIndices($hListView, 1) If UBound($aSelected_Indices) < 2 Then Return SetError(1, 0, "") If $iDirection <> 1 And $iDirection <> -1 Then Return SetError(2, 0, "") Local $iTotal_Items = _GUICtrlListView_GetItemCount($hListView) Local $iTotal_Columns = _GUICtrlListView_GetColumnCount($hListView) Local $iUbound = UBound($aSelected_Indices)-1, $iNum = 1, $iStep = 1 Local $iCurrent_Index, $iUpDown_Index, $sCurrent_ItemText, $sUpDown_ItemText Local $iCurrent_Index, $iCurrent_CheckedState, $iUpDown_CheckedState Local $iImage_Current_Index, $iImage_UpDown_Index If ($iDirection = -1 And $aSelected_Indices[1] = 0) Or _ ($iDirection = 1 And $aSelected_Indices[$iUbound] = $iTotal_Items-1) Then Return SetError(3, 0, "") ControlListView($hListView, "", "", "SelectClear") If $iDirection = 1 Then $iNum = $iUbound $iUbound = 1 $iStep = -1 EndIf For $i = $iNum To $iUbound Step $iStep $iCurrent_Index = $aSelected_Indices[$i] $iUpDown_Index = $aSelected_Indices[$i]+1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1 $iCurrent_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iCurrent_Index) $iUpDown_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iUpDown_Index) _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) For $j = 0 To $iTotal_Columns-1 $sCurrent_ItemText = _GUICtrlListView_GetItemText($hListView, $iCurrent_Index, $j) $sUpDown_ItemText = _GUICtrlListView_GetItemText($hListView, $iUpDown_Index, $j) If _GUICtrlListView_GetImageList($hListView, 1) <> 0 Then $iImage_Current_Index = _GUICtrlListView_GetItemImage($hListView, $iCurrent_Index, $j) $iImage_UpDown_Index = _GUICtrlListView_GetItemImage($hListView, $iUpDown_Index, $j) _GUICtrlListView_SetItemImage($hListView, $iCurrent_Index, $iImage_UpDown_Index, $j) _GUICtrlListView_SetItemImage($hListView, $iUpDown_Index, $iImage_Current_Index, $j) EndIf _GUICtrlListView_SetItemText($hListView, $iUpDown_Index, $sCurrent_ItemText, $j) _GUICtrlListView_SetItemText($hListView, $iCurrent_Index, $sUpDown_ItemText, $j) Next _GUICtrlListView_SetItemChecked($hListView, $iUpDown_Index, $iCurrent_CheckedState) _GUICtrlListView_SetItemChecked($hListView, $iCurrent_Index, $iUpDown_CheckedState) _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index, 0) Next For $i = 1 To UBound($aSelected_Indices)-1 $iUpDown_Index = $aSelected_Indices[$i]+1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1 _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) Next Return 1 EndFunc Edited May 8, 2009 by MrCreatoR  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team
GaryFrost Posted May 8, 2009 Posted May 8, 2009 Ok, here is another version wich preserves the checkbox states and images list of the items:Look in the help for _GUICtrlListView_CopyItems SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
MrCreatoR Posted May 8, 2009 Author Posted May 8, 2009 Look in the help for _GUICtrlListView_CopyItemsI know about that function, thanks. But it's for...Copy Items between 2 list-view controlsAnd this function move the items up / down .P.SPerhaps it could be added to the standard UDFs as well?  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team
GaryFrost Posted May 8, 2009 Posted May 8, 2009 I know about that function, thanks. But it's for...And this function move the items up / down .P.SPerhaps it could be added to the standard UDFs as well?last param "$fDelFlag Delete after copying" would make a move, although it doesn't move items up/down. SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
GaRydelaMer Posted March 26, 2010 Posted March 26, 2010 Hello i have made some change in your function, because i use it in a listview with Group and ItemParam . I have made 2 functions for moving items in last or first position. expandcollapse popup;=============================================================================== ; Function Name: _GUICtrlListView_MoveItems() ; Description: Move selected item(s) in ListView Up or Down. ; ; Parameter(s): $hWnd - Window handle of ListView control (can be a Title). ; $vListView - The ID/Handle/Class of ListView control. ; $iDirection - [Optional], define in what direction item(s) will move: ; 1 (default) - item(s) will move Next. ; -1 item(s) will move Back. ; $sIconsFile - Icon file to set image for the items (only for internal usage). ; $iIconID_Checked - Icon ID in $sIconsFile for checked item(s). ; $iIconID_UnChecked - Icon ID in $sIconsFile for Unchecked item(s). ; ; Requirement(s): #include <GuiListView.au3>, AutoIt 3.2.10.0. ; ; Return Value(s): On seccess - Move selected item(s) Next/Back. ; On failure - Return "" (empty string) and set @error as following: ; 1 - No selected item(s). ; 2 - $iDirection is wrong value (not 1 and not -1). ; 3 - Item(s) can not be moved, reached last/first item. ; ; Note(s): * This function work with external ListView Control as well. ; * If you select like 15-20 (or more) items, moving them can take a while :( (depends on how many items moved). ; ; Author(s): G.Sandler a.k.a CreatoR ([url="http://creator-lab.ucoz.ru"]http://creator-lab.ucoz.ru[/url]) ;=============================================================================== Func My_GUICtrlListView_MoveItems($hWnd, $vListView, $iDirection = 1, $sIconsFile = "", $iIconID_Checked = 0, $iIconID_UnChecked = 0) Local $hListView = $vListView If Not IsHWnd($hListView) Then $hListView = ControlGetHandle($hWnd, "", $hListView) Local $aSelected_Indices = _GUICtrlListView_GetSelectedIndices($hListView, 1) If UBound($aSelected_Indices) < 2 Then Return SetError(1, 0, "") If $iDirection <> 1 And $iDirection <> -1 Then Return SetError(2, 0, "") Local $iTotal_Items = ControlListView($hWnd, "", $hListView, "GetItemCount") Local $iTotal_Columns = ControlListView($hWnd, "", $hListView, "GetSubItemCount") Local $iUbound = UBound($aSelected_Indices) - 1, $iNum = 1, $iStep = 1 Local $iCurrent_Index, $iUpDown_Index, $sCurrent_ItemText, $sUpDown_ItemText Local $iCurrent_CheckedState, $iUpDown_CheckedState Local $iCurrent_GroupId, $iUpDown_GroupId Local $iCurrent_Param, $iUpDown_Param If ($iDirection = -1 And $aSelected_Indices[1] = 0) Or _ ($iDirection = 1 And $aSelected_Indices[$iUbound] = $iTotal_Items - 1) Then Return SetError(3, 0, "") ControlListView($hWnd, "", $hListView, "SelectClear") Local $aOldSelected_IDs[1] Local $iIconsFileExists = FileExists($sIconsFile) If $iIconsFileExists Then For $i = 1 To $iUbound ReDim $aOldSelected_IDs[UBound($aOldSelected_IDs) + 1] _GUICtrlListView_SetItemSelected($hListView, $aSelected_Indices[$i], True) $aOldSelected_IDs[$i] = GUICtrlRead($vListView) _GUICtrlListView_SetItemSelected($hListView, $aSelected_Indices[$i], False) Next ControlListView($hWnd, "", $hListView, "SelectClear") EndIf If $iDirection = 1 Then $iNum = $iUbound $iUbound = 1 $iStep = -1 EndIf For $i = $iNum To $iUbound Step $iStep $iCurrent_Index = $aSelected_Indices[$i] $iUpDown_Index = $aSelected_Indices[$i] + 1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i] - 1 $iCurrent_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iCurrent_Index) $iUpDown_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iUpDown_Index) $iCurrent_GroupId = _GUICtrlListView_GetItemGroupID($hListView, $iCurrent_Index) $iUpDown_GroupId = _GUICtrlListView_GetItemGroupID($hListView, $iUpDown_Index) $iCurrent_Param = _GUICtrlListView_GetItemParam($hListView, $iCurrent_Index) $iUpDown_Param = _GUICtrlListView_GetItemParam($hListView, $iUpDown_Index) _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) For $j = 0 To $iTotal_Columns - 1 $sCurrent_ItemText = _GUICtrlListView_GetItemText($hListView, $iCurrent_Index, $j) $sUpDown_ItemText = _GUICtrlListView_GetItemText($hListView, $iUpDown_Index, $j) _GUICtrlListView_SetItemText($hListView, $iUpDown_Index, $sCurrent_ItemText, $j) _GUICtrlListView_SetItemText($hListView, $iCurrent_Index, $sUpDown_ItemText, $j) Next _GUICtrlListView_SetItemChecked($hListView, $iUpDown_Index, $iCurrent_CheckedState) _GUICtrlListView_SetItemChecked($hListView, $iCurrent_Index, $iUpDown_CheckedState) _GUICtrlListView_SetItemGroupID($hListView, $iUpDown_Index, $iCurrent_GroupId) _GUICtrlListView_SetItemGroupID($hListView, $iCurrent_Index, $iUpDown_GroupId) _GUICtrlListView_SetItemParam($hListView, $iUpDown_Index, $iCurrent_Param) _GUICtrlListView_SetItemParam($hListView, $iCurrent_Index, $iUpDown_Param) If $iIconsFileExists Then If $iCurrent_CheckedState = 1 Then GUICtrlSetImage(GUICtrlRead($vListView), $sIconsFile, $iIconID_Checked, 0) Else GUICtrlSetImage(GUICtrlRead($vListView), $sIconsFile, $iIconID_UnChecked, 0) EndIf If $iUpDown_CheckedState = 1 Then GUICtrlSetImage($aOldSelected_IDs[$i], $sIconsFile, $iIconID_Checked, 0) Else GUICtrlSetImage($aOldSelected_IDs[$i], $sIconsFile, $iIconID_UnChecked, 0) EndIf EndIf _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index, 0) Next For $i = 1 To UBound($aSelected_Indices) - 1 $iUpDown_Index = $aSelected_Indices[$i] + 1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i] - 1 _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) Next EndFunc ;==>My_GUICtrlListView_MoveItems Func My_GUICtrlListView_MoveItemsFirst($hWnd, $vListView) _GUICtrlListView_BeginUpdate($vListView) While _GUICtrlListView_GetSelectedIndices($vListView) > 0 My_GUICtrlListView_MoveItems($hWnd, $vListView, -1) WEnd _GUICtrlListView_EndUpdate($vListView) EndFunc ;==>My_GUICtrlListView_MoveItemsFirst Func My_GUICtrlListView_MoveItemsLast($hWnd, $vListView) _GUICtrlListView_BeginUpdate($vListView) While _GUICtrlListView_GetSelectedIndices($vListView) < _GUICtrlListView_GetItemCount($vListView) - 1 My_GUICtrlListView_MoveItems($hWnd, $vListView, 1) WEnd _GUICtrlListView_EndUpdate($vListView) EndFunc ;==>My_GUICtrlListView_MoveItemsLast
gcue Posted April 15, 2011 Posted April 15, 2011 just wanted to say thanks for the great UDF - works wonderfully.
incepator Posted October 18, 2016 Posted October 18, 2016 Hello, Â Thank you, working fine, but i have a small problem, i have some GUICtrlCreateListViewItem with GUICtrlSetBkColor. Unfortunately this script does not move the color. Â expandcollapse popupFunc _GUICtrlListView_MoveItems($hListView, $iDirection) Local $aSelected_Indices = _GUICtrlListView_GetSelectedIndices($hListView, 1) If UBound($aSelected_Indices) < 2 Then Return SetError(1, 0, "") If $iDirection <> 1 And $iDirection <> -1 Then Return SetError(2, 0, "") Local $iTotal_Items = _GUICtrlListView_GetItemCount($hListView) Local $iTotal_Columns = _GUICtrlListView_GetColumnCount($hListView) Local $iUbound = UBound($aSelected_Indices) - 1, $iNum = 1, $iStep = 1 Local $iCurrent_Index, $iUpDown_Index, $sCurrent_ItemText, $sUpDown_ItemText Local $iCurrent_Index, $iCurrent_CheckedState, $iUpDown_CheckedState Local $iImage_Current_Index, $iImage_UpDown_Index If ($iDirection = -1 And $aSelected_Indices[1] = 0) Or _ ($iDirection = 1 And $aSelected_Indices[$iUbound] = $iTotal_Items - 1) Then Return SetError(3, 0, "") ControlListView($hListView, "", "", "SelectClear") If $iDirection = 1 Then $iNum = $iUbound $iUbound = 1 $iStep = -1 EndIf For $i = $iNum To $iUbound Step $iStep $iCurrent_Index = $aSelected_Indices[$i] $iUpDown_Index = $aSelected_Indices[$i] + 1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i] - 1 $iCurrent_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iCurrent_Index) $iUpDown_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iUpDown_Index) _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) For $j = 0 To $iTotal_Columns - 1 $sCurrent_ItemText = _GUICtrlListView_GetItemText($hListView, $iCurrent_Index, $j) $sUpDown_ItemText = _GUICtrlListView_GetItemText($hListView, $iUpDown_Index, $j) If _GUICtrlListView_GetImageList($hListView, 1) <> 0 Then $iImage_Current_Index = _GUICtrlListView_GetItemImage($hListView, $iCurrent_Index, $j) $iImage_UpDown_Index = _GUICtrlListView_GetItemImage($hListView, $iUpDown_Index, $j) _GUICtrlListView_SetItemImage($hListView, $iCurrent_Index, $iImage_UpDown_Index, $j) _GUICtrlListView_SetItemImage($hListView, $iUpDown_Index, $iImage_Current_Index, $j) EndIf _GUICtrlListView_SetItemText($hListView, $iUpDown_Index, $sCurrent_ItemText, $j) _GUICtrlListView_SetItemText($hListView, $iCurrent_Index, $sUpDown_ItemText, $j) #cs If StringInStr($sCurrent_ItemText, "comment") Then GUICtrlSetBkColor($iUpDown_Index, 0xB15bEA) ElseIf StringInStr($sCurrent_ItemText, "loop") Then GUICtrlSetBkColor($iUpDown_Index, 0xB15bEA) EndIf #ce Next _GUICtrlListView_SetItemChecked($hListView, $iUpDown_Index, $iCurrent_CheckedState) _GUICtrlListView_SetItemChecked($hListView, $iCurrent_Index, $iUpDown_CheckedState) _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index, 0) Next For $i = 1 To UBound($aSelected_Indices) - 1 $iUpDown_Index = $aSelected_Indices[$i] + 1 If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i] - 1 _GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index) Next Return 1 EndFunc ;==>_GUICtrlListView_MoveItems Â
LarsJ Posted October 20, 2016 Posted October 20, 2016 To move the color you have to move the ItemParam value. ItemParam contains the control ID of the listview item. incepator 1 Controls,  File Explorer,  ROT objects,  UI Automation,  Windows Message MonitorCompiled code: Accessing AutoIt variables,  DotNet.au3 UDF,  Using C# and VB codeShell menus: The Context menu,  The Favorites menu. Shell related: Control Panel,  System Image ListsGraphics related: Rubik's Cube,  OpenGL without external libraries,  Navigating in an image,  Non-rectangular selectionsListView controls: Colors and fonts,  Multi-line header,  Multi-line items,  Checkboxes and icons,  Incremental searchListView controls: Virtual ListViews,  Editing cells,  Data display functions
Verssuss Posted March 31, 2020 Posted March 31, 2020 if anybody have that function but move items by dragmove selected items ? im looking v hard for this
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