ControlGet List Selected returns all items

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Penguin
Posts: 94
Joined: 26 Feb 2016, 16:02

ControlGet List Selected returns all items

Post by Penguin » 18 Jan 2022, 09:22

This code returns all the items in the listbox, even if I try Count Selected, Selected, Focused

I only want the selected items. I'm I doing something wrong or is this not possible for some controls?

Code: Select all

ControlGet, SelectedItems, List, Selected, Listbox1, jb search
msgbox, %SelectedItems%
Loop, Parse, SelectedItems, `n  ; Rows are delimited by linefeeds (`n).
{
    RowNumber := A_Index
    Loop, Parse, A_LoopField, %A_Tab%  ; Fields (columns) in each row are delimited by tabs (A_Tab).
        MsgBox Row #%RowNumber% Col #%A_Index% is %A_LoopField%.
}
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: ControlGet List Selected returns all items

Post by mikeyww » 18 Jan 2022, 09:33

ListBox, ComboBox, DropDownList: All the text is retrieved from the control (that is, the ListView options above such as Count and Selected are not supported).

Penguin
Posts: 94
Joined: 26 Feb 2016, 16:02

Re: ControlGet List Selected returns all items

Post by Penguin » 18 Jan 2022, 09:37

Ho do I get just the selected items then?

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: ControlGet List Selected returns all items

Post by mikeyww » 18 Jan 2022, 09:47

Well, hmm, wish I knew that! :problem: Someone here on the forum will know.

just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ControlGet List Selected returns all items

Post by just me » 18 Jan 2022, 10:54

LB_GETSEL message ?

Code: Select all

ControlGet, Items, List, Selected, Listbox1, jb search
SelectedItems := ""
Loop, Parse, Items, `n ; Rows are delimited by linefeeds (`n).
{
   SendMessage, 0x0187, % (A_Index - 1), 0, Listbox1, jb search ; LB_GETSEL
   If (ErrorLevel <> "FAIL") && ((ErrorLevel << 32 >> 32) > 0)
      SelectedItems .= (SelectedItems <> "" ? "`n" : "") . A_LoopField
}
MsgBox, %SelectedItems%
*not tested*

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: ControlGet List Selected returns all items

Post by mikeyww » 18 Jan 2022, 11:06

It worked here. Thanks!

Code: Select all

Gui, Add, ListBox, Multi, A|B|C|D
Gui, Show,, jb search

F3::
ControlGet, Items, List, Selected, Listbox1, jb search
SelectedItems := ""
Loop, Parse, Items, `n ; Rows are delimited by linefeeds (`n). ; From just me
{
   SendMessage, 0x0187, % (A_Index - 1), 0, Listbox1, jb search ; LB_GETSEL
   If (ErrorLevel <> "FAIL") && ((ErrorLevel << 32 >> 32) > 0)
      SelectedItems .= (SelectedItems <> "" ? "`n" : "") . A_LoopField
}
MsgBox, %SelectedItems%
Return

Penguin
Posts: 94
Joined: 26 Feb 2016, 16:02

Re: ControlGet List Selected returns all items

Post by Penguin » 18 Jan 2022, 11:46

Thanks everyone for your help

Post Reply

Return to “Ask for Help (v1)”