Script idea for an expert: typing in list view

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

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

19 Jul 2017, 09:20

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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

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

19 Jul 2017, 09:29

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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 222 guests