cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Dan_K
New Member

Set checkbox based on collection

Hello. I am new to PowerApps and really in need of some help. Your time is appreciate in advance!

I have a gallery with check boxes as the first column. I have most of it figured out except for one thing. 

When the user selects the checkbox it will put the item in a collection. When they unselect it will take it out of the collection. So far too easy. 

My issue is when I filter the gallery to find items I'm looking for, then clear my filters to show all the records in the gallery, items I had check become unchecked....but the are still in the collection. 

How can I keep these check boxes checked even after doing some filtering and then clearing the filtering and All records are showing again. 

1 ACCEPTED SOLUTION

Accepted Solutions
v-chenzhi
Community Support
Community Support

Hi @Dan_K ,

 

I have a test on my side according to your scenario, please try the following workaround.

I create a SharePoint list like this.

vchenzhi_0-1638432369120.png

After setting OnCheck and OnUncheck property,

Set the Default property of CheckBox to:

If(ThisItem.TText exactin CollectionSelectedItems.TText,true)

vchenzhi_1-1638432490774.png

 

 

Best Regards,

Zhi Chen

 

 

View solution in original post

4 REPLIES 4
poweractivate
Community Champion
Community Champion

@Dan_K 

 

What is value of the OnSelect of the Checkbox? I also presume the Checkbox is inside the Gallery?

 

What is the value of Items for the Gallery?

 

As a guess even without knowing the above, the Gallery might have Items referencing a Data source, but the Checkbox updates some other Collection that is not related to the Gallery at all. Another guess is that the Checkbox is somehow not actually updating the Collection.

Thanks for chiming in! Here is what I have so far....

OnCheck: Collect(CollectionSelectedItems,This item)

OnSelect: Select(Parent)

OnUncheck: Remove(CollectionSelectedItem.ThisItem)

 

You are correct that the checkbox is in the gallery. So that way every line in the gallery has its own checkbox allowing the user to select individual items. 

 

The value of the items in the gallery are just text values. 

 

The datasource for the gallery is pointing to a SharePoint list. Though not my ideal source it's all I have for the moment lol. 

 

Just for clarify. When I click the check box I looked at the collection and all items selected in the gal appear in the collection. If I unclick the box the item will be removed from the collection. All good here so far.

Again my hang up is when I have items selected, then filter the gallery to continue look through records, I then clear my filters when done searching for items I want to select...when the gallery go back to it's original state all my selected boxes become unselected. However the items that were selected (now showing unselected) still show up in the collection. Therefore if I selected the items again I now get duplicate items in the collection. 

 

Hope this gives you what you need and then some. Feel free to ask any additional questions and thanks again for your assistance!

v-chenzhi
Community Support
Community Support

Hi @Dan_K ,

 

I have a test on my side according to your scenario, please try the following workaround.

I create a SharePoint list like this.

vchenzhi_0-1638432369120.png

After setting OnCheck and OnUncheck property,

Set the Default property of CheckBox to:

If(ThisItem.TText exactin CollectionSelectedItems.TText,true)

vchenzhi_1-1638432490774.png

 

 

Best Regards,

Zhi Chen

 

 

View solution in original post

Hi @v-chenzhi 

Thanks for your reply. Apologize for this long reply but I feel the detail is needed. I tried your approach and it did work, but there's a catch unfortunately. 

So I selected my initial items. I then checked the collection to verify everything was captured. All good so far. I then filtered the gallery to find additional records. I selected the additional records I wanted then cleared my filters so the gallery would revert back to it's original look.

My original selections remain selected per your formula. However once I unchecked them, they did not get removed from the collection.

This was unfortunate but I was able to use your formula to create a solution.

I created a label in the gal. So now each item has the label. I set the label text to say "added" using your formula. So now when I check the box, the checkbox visible is false and the label visible is true with the text property "added" to inform the user the item has been selected. 

I then created a button "show selected" which brings up a pop-up object with a gal connected to the collection and gives the user ability to remove the items via the pop up. When they remove the items from the pop up, the label visible property in the gal visible becomes false and the check box visible becomes true defaulted to false. 

Not the ideal approach but I was able to use your formula to make a solution. I will mark this as solved in hopes that's this helps others. But if you have any other suggestions please post them as I am not sure my approach is the best. But it works. Thank you again!!!!!

 

 

 

 

 

 

 

 

 

 

 

 

 

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (3,412)