Fill array or collection with checkbox click in listview

User avatar
sal21
PlatinumLounger
Posts: 4357
Joined: 26 Apr 2010, 17:36

Fill array or collection with checkbox click in listview

Post by sal21 »

Based a checkbox on listview i need to filla array or collection based a click on...

Example:

click on checkbox on row 4, is true in this case, fill array or collection with the related value in column 1
click on checkbox on row 14, is true in this case, append the related value of array or collection, with the related value in column 1
ecc...

if i reclick on, checkbox,is false in this case, on row 4, delete the related value, in the array or collection
ecc...

how to?

Hope understand me.

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Fill array or collection with checkbox click in listview

Post by HansV »

Declare a variable Dict of type Object:

Code: Select all

Dim Dict As Object
In the Load event of the form, add the line

Code: Select all

    Set Dict = CreateObject("Scripting.Dictionary")
Create an event procedure for the ItemCheck event of the ListView control:

Code: Select all

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    If Item.Checked Then
        Dict.Add Item:=Item.Text, Key:=Item.Text
    Else
        Dict.Remove Key:=Item.Text
    End If
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4357
Joined: 26 Apr 2010, 17:36

Re: Fill array or collection with checkbox click in listview

Post by sal21 »

HansV wrote:
16 Mar 2023, 16:27
Declare a variable Dict of type Object:

Code: Select all

Dim Dict As Object
In the Load event of the form, add the line

Code: Select all

    Set Dict = CreateObject("Scripting.Dictionary")
Create an event procedure for the ItemCheck event of the ListView control:

Code: Select all

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    If Item.Checked Then
        Dict.Add Item:=Item.Text, Key:=Item.Text
    Else
        Dict.Remove Key:=Item.Text
    End If
End Sub
FEW LINES, BIG CODE!
tks bro