[ListView] Get number of selected items (in realtime)

Put simple Tips and Tricks that are not entire Tutorials in this forum
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

[ListView] Get number of selected items (in realtime)

25 Aug 2021, 07:22

Get number of selected items in ListView (in realtime)

Check for the LVN_ITEMCHANGED ListView Notifications code and call LV.GetCount("S") (same as send the LVM_GETSELECTEDCOUNT Message to the ListView control)

Code: Select all

MyGui := Gui()
LV := MyGui.Add("ListView", "w300 r8 Grid -LV0x10", ["Column1", "Column2", "Column3"])
loop 7
	LV.Add(, A_Index * 1, A_Index * 2, A_Index * 3)
LV.OnNotify(LVN_ITEMCHANGED := -101, LV_CountSelectedItems)
MyGui.Show()


LV_CountSelectedItems(LV, *)
{
	MyGui.Title := "[" LV.GetCount("S") " / " LV.GetCount() "]"
}


/*
LVM_GETSELECTEDCOUNT(handle)   ; same as LV.GetCount("S")
{
	static LVM_FIRST            := 0x1000
	static LVM_GETSELECTEDCOUNT := LVM_FIRST + 50

	return SendMessage(LVM_GETSELECTEDCOUNT, 0, 0, handle)
}
*/

Image


Works also with selecting by SHIFT + ARROW or CTRL + ARROW and ContextMenu with LV.Modify(0, "Select")
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
kczx3
Posts: 1642
Joined: 06 Oct 2015, 21:39

Re: [ListView] Get number of selected items

25 Aug 2021, 13:23

What's wrong with using LV.GetCount("S")?
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: [ListView] Get number of selected items

26 Aug 2021, 00:56

Huuu.. why does I missed the "S" option all the years. :shock:
Anyway. Changed the example and thank you for the hint
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
kczx3
Posts: 1642
Joined: 06 Oct 2015, 21:39

Re: [ListView] Get number of selected items (in realtime)

26 Aug 2021, 18:55

:D no problem! I’m loving seeing all the v2 love these days! Should help with getting more and more users to move over
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [ListView] Get number of selected items (in realtime)

21 Apr 2022, 00:37

What's wrong with using LV.OnEvent("ItemSelect", LV_CountSelectedItems)?
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: [ListView] Get number of selected items (in realtime)

21 Apr 2022, 01:58

Probably the lack of reading the documentation. ;)
Any way, thanks for the hint.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 57 guests