On a single-select ListBox, LB_SETCURSEL worked.
Code: Select all
q::
vIndex := 3
ControlGet, hCtl, Hwnd,, ListBox1, A
;on single-select listbox:
;did nothing:
;PostMessage, 0x19E, % vIndex-1, 0,, % "ahk_id " hCtl ;LB_SETCARETINDEX := 0x19E
;set focus and selection (worked):
PostMessage, 0x186, % vIndex-1, 0,, % "ahk_id " hCtl ;LB_SETCURSEL := 0x186
;on multi-select listbox:
;set focus but not selection:
;PostMessage, 0x19E, % vIndex-1, 0,, % "ahk_id " hCtl ;LB_SETCARETINDEX := 0x19E
;did nothing:
;PostMessage, 0x186, % vIndex-1, 0,, % "ahk_id " hCtl ;LB_SETCURSEL := 0x186
return