Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

_GUICtrlListView_MoveItems - UDF


  • Please log in to reply
10 replies to this topic

#1 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 17 January 2008 - 04:13 AM

AutoIt         
;=============================================================================== ; 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 (<a href='http://creator-lab.ucoz.ru' class='bbc_url' title='External link' rel='nofollow external'>http://creator-lab.ucoz.ru</a>) ;=============================================================================== 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

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image 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 ProgramPosted Image UDFs: 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 UDFPosted Image 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team








#2 Siao

Siao

    RTFM, foo!

  • Active Members
  • PipPipPipPipPipPip
  • 937 posts

Posted 17 January 2008 - 12:02 PM

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 by Siao, 17 January 2008 - 12:35 PM.

"be smart, drink your wine"

#3 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 17 January 2008 - 02:50 PM

Hi,

Not sure what's the purpose of $sIconsFile and other 2 parameters that follow it, but your func doesn't support images

It does support, but just images direct from file, in the old way :D - GUICtrlSetImage still work i think :P
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.
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image 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 ProgramPosted Image UDFs: 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 UDFPosted Image 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#4 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 08 May 2009 - 11:40 AM

Ok, here is another version wich preserves the checkbox states and images list of the items:

AutoIt         
;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

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image 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 ProgramPosted Image UDFs: 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 UDFPosted Image 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#5 yehia

yehia

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 275 posts

Posted 08 May 2009 - 04:17 PM

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 by yehia, 08 May 2009 - 04:19 PM.


#6 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 08 May 2009 - 04:48 PM

can this func manipulate external script's LV?

Yes:

AutoIt         
;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 by MrCreatoR, 08 May 2009 - 04:49 PM.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image 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 ProgramPosted Image UDFs: 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 UDFPosted Image 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#7 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 08 May 2009 - 04:50 PM

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.


#8 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 08 May 2009 - 05:04 PM

Look in the help for _GUICtrlListView_CopyItems


I know about that function, thanks. But it's for...

Copy Items between 2 list-view controls


And this function move the items up / down ^_^.

P.S
Perhaps it could be added to the standard UDFs as well?
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image 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 ProgramPosted Image UDFs: 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 UDFPosted Image 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#9 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 08 May 2009 - 05:15 PM

I know about that function, thanks. But it's for...


And this function move the items up / down ^_^.

P.S
Perhaps 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.


#10 GaRydelaMer

GaRydelaMer

    Seeker

  • Active Members
  • 27 posts

Posted 26 March 2010 - 12:58 AM

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.


AutoIt         
;=============================================================================== ; 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


#11 gcue

gcue

    just a wannabe

  • Active Members
  • PipPipPipPipPipPip
  • 1,904 posts

Posted 15 April 2011 - 02:28 PM

just wanted to say thanks for the great UDF - works wonderfully.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users