Jump to content

Need Assistance in Selecting a Listbox Item


Recommended Posts

Hello Everyone,

I am having a bit of an issue developing a script to select an item in a third party listbox.  I have made several functional AutoIt scripts prior to this post and I have spent over half a day so far trying to get this working.  I've googled and forum searched and cannot find anything specific to my issue.  Any insight you may have would be greatly appreciated.

Basically, I need this script to look for a listbox called "Check Name" and select a specific item in the listbox.  The item is in an external text file, which is being assigned to a variable.  The script currently runs, but it selects the first item in the list.  I need it to select a specific item which will definitely be in the list, but the item's position in the list will change at random.

I know my issue lies within the "ControlGetHandle" or "_guidctrllistbox_clickitem" lines.  I just can't figure out what I need to put there to get the script to select the item I tell it to select.

$namefile = FileOpen("C:\Name.txt", 0)
$name = FileReadLine($namefile, 1)
#include <GuiListBox.au3>
If WinExists("Check Name", "") Then
    WinActivate("Check Name", "")
    WinWaitActive("Check Name", "")
    ControlGetHandle("Check Name", "", "[Class: Listbox, INSTANCE 1]")
    _guictrllistbox_clickitem($name, 1, "left")
    Send("{Enter}")
EndIf
FileClose("Name.txt")
FileDelete("C:\Name.txt")

Thank you for viewing my question.

Link to comment
Share on other sites

mikeII,

Thank you for the quick reply to my thread.  I read up on your suggestions and this is what I have come up with.  Unfortunately, I am still not able to get the script to highlight and select the name in the Listbox.  Here is the code which I have changed:

ElseIf WinExists("Check Name", "") Then
    WinActivate("Check Name", "")
    WinWaitActive("Check Name", "")
    $hListBox = ControlGetHandle("Check Name", "", "[Class: Listbox, INSTANCE 1]")
    $iIndex = _GUICtrlListBox_FindInText ($hListBox, $name)
    _GUICtrlListBox_SetCurSel ($hListBox, $iIndex)

If you have any additional advice I would appreciate it.

Thank you.

Edited by TastyWheat
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...