Nanaki Posted May 29, 2006 Share Posted May 29, 2006 Topic says it all. I want to create a ListView with two buttons "up" and "down". Clicking them will move the selected ListViewItem up or down. Is it possible? Thanks in advance, Link to comment Share on other sites More sharing options...
Gyzmok Posted May 30, 2006 Share Posted May 30, 2006 (edited) I did something like that in this tool (see screenshot) :http://www.autoitscript.com/forum/index.php?showtopic=26457This is an example for 4 columns (the first column is a checkbox)Looks like this : expandcollapse popupFunc _upmove() if _GUICtrlListViewGetSelectedCount ($mylist) = 1 and _GUICtrlListViewGetSelectedIndices ($mylist) <> 0 then $curindex = _GUICtrlListViewGetSelectedIndices ($mylist) $col0 = _GUICtrlListViewGetCheckedState($mylist,$curindex-1) $col1 = _GUICtrlListViewGetItemText ($mylist,$curindex-1,1) $col2 = _GUICtrlListViewGetItemText ($mylist,$curindex-1,2) $col3 = _GUICtrlListViewGetItemText ($mylist,$curindex-1,3) _GUICtrlListViewSetCheckState ($mylist,$curindex-1,_GUICtrlListViewGetCheckedState($mylist,$curindex+0)) _GUICtrlListViewSetItemText ($mylist,$curindex-1,1,_GUICtrlListViewGetItemText ($mylist,$curindex+0,1)) _GUICtrlListViewSetItemText ($mylist,$curindex-1,2,_GUICtrlListViewGetItemText ($mylist,$curindex+0,2)) _GUICtrlListViewSetItemText ($mylist,$curindex-1,3,_GUICtrlListViewGetItemText ($mylist,$curindex+0,3)) ; _GUICtrlListViewSetCheckState($mylist,$curindex-0,$col0) _GUICtrlListViewSetItemText ($mylist,$curindex-0,1,$col1) _GUICtrlListViewSetItemText ($mylist,$curindex-0,2,$col2) _GUICtrlListViewSetItemText ($mylist,$curindex-0,3,$col3) ; _GUICtrlListViewSetItemSelState ($mylist,$curindex-1,1) _GUICtrlListViewSetItemSelState ($mylist,$curindex-0,0) EndIf EndFunc;==>_upmove ; Func _downmove() if _GUICtrlListViewGetSelectedCount ($mylist) = 1 and _GUICtrlListViewGetSelectedIndices ($mylist) <> _GUICtrlListViewGetItemCount($mylist)-1 then $curindex = _GUICtrlListViewGetSelectedIndices ($mylist) $col0 = _GUICtrlListViewGetCheckedState($mylist,$curindex+1) $col1 = _GUICtrlListViewGetItemText ($mylist,$curindex+1,1) $col2 = _GUICtrlListViewGetItemText ($mylist,$curindex+1,2) $col3 = _GUICtrlListViewGetItemText ($mylist,$curindex+1,3) _GUICtrlListViewSetCheckState ($mylist,$curindex+1,_GUICtrlListViewGetCheckedState($mylist,$curindex+0)) _GUICtrlListViewSetItemText ($mylist,$curindex+1,1,_GUICtrlListViewGetItemText ($mylist,$curindex+0,1)) _GUICtrlListViewSetItemText ($mylist,$curindex+1,2,_GUICtrlListViewGetItemText ($mylist,$curindex+0,2)) _GUICtrlListViewSetItemText ($mylist,$curindex+1,3,_GUICtrlListViewGetItemText ($mylist,$curindex+0,3)) ; _GUICtrlListViewSetCheckState($mylist,$curindex-0,$col0) _GUICtrlListViewSetItemText ($mylist,$curindex-0,1,$col1) _GUICtrlListViewSetItemText ($mylist,$curindex-0,2,$col2) _GUICtrlListViewSetItemText ($mylist,$curindex-0,3,$col3) ; _GUICtrlListViewSetItemSelState ($mylist,$curindex+1,1) _GUICtrlListViewSetItemSelState ($mylist,$curindex-0,0) EndIf EndFunc;==>_downmove Edited June 2, 2006 by Gyzmok D2charkeeper = No more 'expired characters' in D2.File Date Changer = Change the file date(s), attributes and the filename case of multiple files @ once.Updater_full = Copy/Update your autoitscripts, pictures, .mp3, .avi etc ... subdirs from your PC to your memory stick or to your external harddisk. Now with scheduling and logging.Questmapper Link to comment Share on other sites More sharing options...
Aceguy Posted September 14, 2006 Share Posted September 14, 2006 i fink i simplified it a bit. Case $msg = $up If _GUICtrlListViewGetSelectedCount($listview) = 1 And _GUICtrlListViewGetSelectedIndices($listview) + 1 > 1 Then $curindex = _GUICtrlListViewGetSelectedIndices($listview) For $x = 0 To _GUICtrlListViewGetSubItemsCount($listview) $x_i = _GUICtrlListViewGetItemText($listview, $curindex - 1, $x) _GUICtrlListViewSetItemText($listview, $curindex - 1, $x, _GUICtrlListViewGetItemText($listview, $curindex + 0, $x)) _GUICtrlListViewSetItemText($listview, $curindex - 0, $x, $x_i) Next _GUICtrlListViewSetItemSelState($listview, $curindex - 1, 1) _GUICtrlListViewSetItemSelState($listview, $curindex - 0, 0) EndIf Case $msg = $down If _GUICtrlListViewGetSelectedCount($listview) = 1 And _GUICtrlListViewGetSelectedIndices($listview) + 1 < _GUICtrlListViewGetItemCount($listview) Then $curindex = _GUICtrlListViewGetSelectedIndices($listview) For $x = 0 To _GUICtrlListViewGetSubItemsCount($listview) $x_i = _GUICtrlListViewGetItemText($listview, $curindex + 1, $x) _GUICtrlListViewSetItemText($listview, $curindex + 1, $x, _GUICtrlListViewGetItemText($listview, $curindex + 0, $x)) _GUICtrlListViewSetItemText($listview, $curindex - 0, $x, $x_i) Next _GUICtrlListViewSetItemSelState($listview, $curindex + 1, 1) _GUICtrlListViewSetItemSelState($listview, $curindex - 0, 0) EndIf [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
florisch Posted March 22, 2007 Share Posted March 22, 2007 I did not test that, but how about this: - get text of selected item - get index of selected item - delete selected item - insert new item with text at desired position The functions to do this exist: _GUICtrlListViewGetItemText($h_listview[, $i_Item=-1[, $i_SubItem=-1]]) _GUICtrlListViewGetSelectedIndices($h_listview[, $i_ReturnType=0])) _GUICtrlListViewDeleteItem($h_listview, $i_index) _GUICtrlListViewInsertItem($h_listview, $i_index, $s_text) Link to comment Share on other sites More sharing options...
MrCreatoR Posted March 22, 2007 Share Posted March 22, 2007 Hi, Here is the quickly, and i think most effective way to do this: #include <GUIConstants.au3> #include <GuiListView.au3> $Gui = GUICreate('Test Up&Down ListView', 300, 300) $Listview = GUICtrlCreateListView("Column1|Column2", 20, 20) For $i = 1 To 5 GUICtrlCreateListViewItem("Item "&$i&"|Item "&$i&" subtext", $Listview) Next $Up = GUICtrlCreateButton("Up", 20, 180) $Down = GUICtrlCreateButton("Down", 90, 180) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case -3 ExitLoop Case $Up $Index = _GUICtrlListViewGetCurSel($Listview) $SelText = _GUICtrlListViewGetItemText($Listview) If $SelText = "" Or $Index = 0 Then ContinueLoop _GUICtrlListViewDeleteItem($Listview, $Index) _GUICtrlListViewInsertItem($Listview, $Index-1, $SelText) ControlListView($Gui, "", $Listview, "Select", $Index-1, $Index-1) Case $Down $Index = _GUICtrlListViewGetCurSel($Listview) $SelText = _GUICtrlListViewGetItemText($Listview) If $SelText = "" Or $Index+1 = _GUICtrlListViewGetItemCount($Listview) Then ContinueLoop _GUICtrlListViewDeleteItem($Listview, $Index) _GUICtrlListViewInsertItem($Listview, $Index+1, $SelText) ControlListView($Gui, "", $Listview, "Select", $Index+1, $Index+1) EndSwitch WEnd 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 Link to comment Share on other sites More sharing options...
florisch Posted March 23, 2007 Share Posted March 23, 2007 Hi, Here is the quickly, and i think most effective way to do this:Thanks, thats exactly what I thought about. This was not on my to do list, but nice to have. Therefore I must admit that I will use your code. One little change: since I dont like large GUI message loops, I put the 6 lines of interest in a function: #include <GUIConstants.au3> #include <GuiListView.au3> $Gui = GUICreate('Test Up&Down ListView', 300, 300) $Listview = GUICtrlCreateListView("Column1|Column2", 20, 20) For $i = 1 To 5 GUICtrlCreateListViewItem("Item "&$i&"|Item "&$i&" subtext", $Listview) Next $Up = GUICtrlCreateButton("Up", 20, 180) $Down = GUICtrlCreateButton("Down", 90, 180) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case -3 ExitLoop Case $Up _updown(-1) Case $Down _updown( 1) EndSwitch WEnd func _updown($i) $Index = _GUICtrlListViewGetCurSel($Listview) $SelText = _GUICtrlListViewGetItemText($Listview) If ($SelText = "") Or ($Index + $i < 0) Or ($Index + $i >= _GUICtrlListViewGetItemCount($Listview) ) Then Return _GUICtrlListViewDeleteItem($Listview, $Index) _GUICtrlListViewInsertItem($Listview, $Index + $i, $SelText) ControlListView($Gui, "", $Listview, "Select", $Index + $i, $Index + $i) endfunc 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