zvd Posted February 6, 2007 Posted February 6, 2007 Hello, I have a List control where I can click/highlight an item in the list, then click a button to either move the item up or down in the list. How can I retain focus on the item clicked so it will keep moving up/down the list with every button click? This example requires me to click the item every time before the button is pushed. expandcollapse popup#include <GUIConstants.au3> #Include <GuiList.au3> Global $strList getinfo() #Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\SciTE\Koda\Forms\list-test.kxf $Form1 = GUICreate("AForm1", 331, 274, 193, 115) $List1 = GUICtrlCreateList("", 32, 32, 225, 162) GUICtrlSetData(-1, $strList) GUICtrlSetState($List1, $GUI_FOCUS) $Button1 = GUICtrlCreateButton("p", 280, 64, 25, 41, 0) GUICtrlSetFont(-1, 10, 400, 0, "Wingdings 3") $Button2 = GUICtrlCreateButton("q", 280, 120, 25, 41, 0) GUICtrlSetFont(-1, 10, 400, 0, "Wingdings 3") $Button3 = GUICtrlCreateButton("OK", 72, 216, 57, 25, 0) $Button4 = GUICtrlCreateButton("Cancel", 156, 215, 57, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 moveup() Case $Button2 movedown() Case $Button3 gnstring() Case $Button4 Exit EndSwitch WEnd Func getinfo() $objWord = ObjCreate("Word.Application") $colTasks = $objWord.Tasks For $objTask In $colTasks If $objTask.Visible Then $strList = ($strList & $objTask.Name & "|") Next $objWord.Quit EndFunc Func moveup() $sel = _GUICtrlListSelectedIndex($List1) $repl = ($sel - 1) $mv = _GUICtrlListSwapString($List1, $sel, $repl) EndFunc Func movedown() $sel = _GUICtrlListSelectedIndex($List1) $repl = ($sel + 1) $mv = _GUICtrlListSwapString($List1, $sel, $repl) EndFunc Func gnstring() For $i = 0 To _GUICtrlListCount($List1) - 1 If $i = 0 Then $nstrList = _GUICtrlListGetText($List1, $i) Else $nstrList = $nstrList & @CRLF & _GUICtrlListGetText($List1, $i) EndIf Next MsgBox(0, "", $nstrList) EndFunc
quaizywabbit Posted February 6, 2007 Posted February 6, 2007 search the forum for "Draglist" [u]Do more with pre-existing apps![/u]ANYGUIv2.8
PaulIA Posted February 8, 2007 Posted February 8, 2007 Try this... Func moveup() $sel = _GUICtrlListSelectedIndex($List1) $repl = ($sel - 1) $mv = _GUICtrlListSwapString($List1, $sel, $repl) _GUICtrlListSelectIndex($List1, $repl) EndFunc Func movedown() $sel = _GUICtrlListSelectedIndex($List1) $repl = ($sel + 1) $mv = _GUICtrlListSwapString($List1, $sel, $repl) _GUICtrlListSelectIndex($List1, $repl) EndFunc Auto3Lib: A library of over 1200 functions for AutoIt
zvd Posted February 9, 2007 Author Posted February 9, 2007 Yay! That works great. It's exactly what I was trying to accomplish. Thanks so much PaulIA!
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