Jump to content

Problem with SetCurrentSelection- in a ComboBox

Recommended Posts

(moved from General support forum- accidental post)

I"m having a problem with SetCurrentSelection.

I can see on the screen that my combo box has the string I am searching for, and I am displaying that

value in a msgbox, so why isn't the select working with SetCurrentSelection?

;$bankNumber is equal to 1 when this code is called, and the first entry in the combo box is a 1 (at index 0)

$WinRet = ControlFocus($BankUploadWindowTitle, "", $ControlID)

msgbox(0x20,"Set bank number", "String($BankNumber)=" & String($BankNumber) )

$Ref = ControlCommand($BankUploadWindowTitle, "", $ControlID, "FindString", String($BankNumber))

if (($Ref <> - 1) and (Not @error)) Then

$WinRet = ControlCommand($BankUploadWindowTitle, "", $ControlID, "SetCurrentSelection", $Ref)

Msgbox(0x20,"SetBankNumber4", "$Ref from FindString=" & String($Ref))


Link to post
Share on other sites

As an alternative to ControlCommand() function, you can use DllCall() to select an item in a ComboBox

DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int", 0)

Where $h_combobox handle can be get using ControlGetHandle()

$i_index is the index of the item you want to select



Open Date/Time properties from Control Panel.

This script will select the item from the month combo box based on i_index value.

Global Const $CB_SETCURSEL = 0x14E
$h_combobox = ControlGetHandle("Date and Time Properties", "", 713)
$i_index = 2   ; March
DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int", 0)
Edited by tonedeaf
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...