ChooseItem
Windows management function.
The ChooseItem function selects an item in a listbox or combobox.
Usage
Used to select an item from a listbox, a combobox, a tree view, a list view or a toolbar. If the Windows control is not a standard one, ChooseItem will not work. In such a case, you can try ClickOnText function or ClickOnTextOCR function or use multiple SendKeys("<Down>") and a last SendKeys("<Enter>") for selecting the desired item.
Syntax
ChooseItem(list,<id>,<item>,single[,<button>][,shift|ctrl])
ChooseItem(combo,<id>,<item>,single[,<button>])
ChooseItem(treeview,<id>,<item>,single or expand[,<button>])
ChooseItem(listview,<id>,<item>,single[,<button>][,shift|ctrl])
ChooseItem(toolbar,<id>,<item>,dropdown[,<button>])or
ret=ChooseItem(list,<id>,<item>,single[,<button>])
ret=ChooseItem(combo,<id>,<item>,single[,<button>])
ret=ChooseItem(treeview,<id>,<item>,single or expand[,<button>])
ret=ChooseItem(listview,<id>,<item>,single[,<button>])
ret=ChooseItem(toolbar,<id>,<item>,dropdown[,<button>])Parameters
list, combo, treeview, listview,toolbar : keywords defining the list type. Toolbar and dropdown keywords are used to navigate in special menus of Explorer or IE as below :
UseWindow("EXPLORER.EXE|SysPage|Explorer - C:\|2",1)
ChooseItem(ToolBar,"|1","&Display",dropdown,left)
UseWindow("EXPLORER.EXE|ExploreWClass|Exploring - C:\",1)
ChooseMenu(Context,"&List")<id>, identifier of the list ; it can be a variable.
<item>, item to be selected in the list ; it can be a variable.
single (or double) : keyword for either a selection by a single click or a double click.
expand : keyword to expand a branch (for instance, clicking the + icon in Explorer).
<button>, mouse button used for the action (left or right). If this parameter is not present, left is assumed.
shift or ctrl : in a list/listview, when a multiple selection is done, the shift keyword is used for the last item selected, or the ctrl keyword is used for each individual item selected.
Return value
Ret, numeric return code. When successful, the function returns 0, otherwise use this return code for Error Handling.
Remarks
If you need to choose an item in systray (the notification area on the right part of taskbar), the WinTask icons in the systray interfere with the generated chooseitem. Use the code below instead of ChooseItem for selecting an icon in systray:
#HideTrayIcon=1
pause 2
UseWindow("EXPLORER.EXE|TrayNotifyWnd")
pause 10 ticks
SendKeys("<Tab>",NoActivate)
Example code
This script shows the different uses of the statement ChooseItem in Explorer or in Windows control panel.
'ChooseItem(Treeview, )
shell("explorer.exe")
'click on Recycle Bin
msgbox("WinTask simulates a click on Recycle Bin")
UseWindow("EXPLORER.EXE|ReBarWindow32|My Documents|2",1)
ChooseItem(TreeView, "1", "Recycle Bin", single, left )
pause 3
CloseWindow("EXPLORER.EXE|ExploreWClass|Recycle Bin",1)
'ChooseItem(Listview, ) and ChooseItem(Combo, )
pause 2
shell("control.exe")
UseWindow("EXPLORER.EXE|SHELLDLL_DefView|Control Panel|1",1)
MsgBox("WinTask simulates a click on Date and Time")
ChooseItem(ListView,"1","Date and Time",double,left)
pause 1
UseWindow("RUNDLL32.EXE|#32770|Date && Time",1)
MsgBox("WinTask simulates the selection of November in a Combobox")
ChooseItem(Combo,"1","November",single,left)
pause 1
UseWindow("RUNDLL32.EXE|#32770|Date and Time Properties",1)
Click(Button,"Cancel")
'ChooseItem(Toolbar, )
UseWindow("EXPLORER.EXE|ReBarWindow32|Control Panel|1",1)
ChooseItem(ToolBar, "|2", "&Tools", dropdown, left )
UseWindow("EXPLORER.EXE|CabinetWClass|Control Panel",1)
ChooseMenu(Context,"Folder &Options...")
UseWindow("EXPLORER.EXE|#32770|Folder Options",1)
Click(Button,"Cancel")
CloseWindow("EXPLORER.EXE|CabinetWClass|Control Panel",1)