Page 2 of 2

Re: Script idea for an expert: typing in list view

Posted: 19 Jul 2017, 09:20
by jeeswg
I created a ListBox (Windows 7), and didn't have this problem:

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

Re: Script idea for an expert: typing in list view

Posted: 19 Jul 2017, 09:29
by jeeswg
OK, AFAICS, the PostMessage by itself should work, if it's a single-select ListBox, otherwise, you could try the code below on a single-select ListBox:

Note the various things to try:
;LBN_SELCHANGE := 1
;LBN_SETFOCUS := 4

;LB_SETCARETINDEX := 0x19E
;LB_SETCURSEL := 0x186

Code: Select all

vIndex := 3
ControlGet, hCtl, Hwnd,, ListBox1, A
PostMessage, 0x186, % vIndex-1, 0,, % "ahk_id " hCtl ;LB_SETCURSEL := 0x186

;LBN_SELCHANGE := 1
;LBN_SETFOCUS := 4
vNum := 1
;vNum := 4

vCtlID := DllCall("user32\GetDlgCtrlID", Ptr,hCtl)
hWndParent := DllCall("user32\GetParent", Ptr,hCtl, Ptr)
SendMessage, 0x111, % vCtlID | (vNum << 16), % hCtl, , % "ahk_id " hWndParent ;WM_COMMAND
return
I also have some ListBox selection functions that may be useful (e.g. for a multi-select ListBox):
GUI COMMANDS: COMPLETE RETHINK (latest: get/set system fonts, ComboBox choose string notify) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 01#p124201