Question

I am using AutoIt to create an auto-install application. There is an dialog which contains a ListBox control, and in the listbox there are some choices for user (the detailed choices depends on user's machine. For some users there maybe only one choice, for some users there may be three choices, etc.), so I want to get the texts in the listbox to make the decision. I have tried the following code, but it did not work.

; 2223 is the ID of listbox

$txt = ControlGetText("Select Web Site", "", "[ID:2223]")
Msgbox(0, "", $txt)

After execution $txt is null.

So what should I do to get the texts in Listbox?

Here is the attribute of the listbox monitored by AutoIt v3 Window Info:

Class: WindowsForms10.Listbox.app.0.33c0d9d
Was it helpful?

Solution 4

What I want to do is to select one of the items named "Default Web Site" in the list, but it seems that the list content can not be got, so finally I tried another way:

At first I make the listbox focused, and then I choose the item "Default Web Site" by sending "Def":

ControlFocus($Title, "", "[NAME:lbWebSites]")
; Select the option "Default Web Site", so press "def" to set the desired item.
Send("Def")

OTHER TIPS

I've found the 'Send' command to be unreliable on occasion, particularly if the PC is locked.

'ControlSend' has always worked to get the keystrokes where I want them.

I wrote a test to check to see if an item was in a combo box. There might be similar functions for list boxes using GuiComboBox.au3.

Func DoesItemExistInComboBox($windowtitle, $windowtext, $comboboxcontrol, $itemtocheck)
    $returnvalue = 0
    $ComboBoxHandle = ControlGetHandle($windowtitle, $windowtext, $comboboxcontrol)
    $ComboBoxArray = _GUICtrlComboBox_GetListArray($ComboBoxHandle)
    For $i = 0 TO UBound($ComboBoxArray)-1
        If $ComboBoxArray[$i] = $itemtocheck Then
           $returnvalue = 1
        EndIf
    Next
    return $returnvalue
EndFunc

What about:

ControlCommand("My GUI", "", "[CLASS:ListBox; INSTANCE:1]", "SelectString", "item2")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top