Showing results for 
Search instead for 
Did you mean: 
Helper II
Helper II

Issue to add/ remove item to collection with button

Hi all, 


I have a Checkbox gallery that is automatically set to all checked if a certain value of dropdown is selected. However, whenever I try to uncheck items and add to the collection, the checkbox checked all the items and add to the gallery. I couldn't uncheck item that I don't need from the gallery. Here are the logic that I set for my buttons, checkbox and gallery. 


Checkbox property:



Default  = If(DataCardValue1.Selected.Value = 'TableDropdownName''.Yes, true,false)
OnCheck = Collect(Collection,ThisItem)
OnUncheck = Remove(Collection,ThisItem)



I also have a Clear button and Add to Collection button that let users to uncheck the checkbox before adding to collection. 

Clear button: 



If(DataCardValue11.Selected.Value = 'TableDropdownName'.Yes Or DataCardValue1.Selected.Value = 'TableDropdownName'.No, true, false) 


Add to Collection button: 


ForAll(Filter(Gallery.AllItems,Checkbox1.Value = true),







Try one of two things, with #2 being more preferable if it works

1. Try to add All to the end of  the Remove

Checkbox property:


OnUncheck = Remove(Collection,ThisItem, All)



2. Try to change Collect to Patch below - and keep the OnUncheck as Remove like you had before:

Checkbox property:


OnCheck = Patch(Collection,ThisItem)
OnUncheck = Remove(Collection,ThisItem)




See if it helps @Xinlin 

Hi @poweractivate, thanks for helping out. I've tried both of the solutions but unfortunately it doesn't seem to work. 


I guess the reason that causing the problem would be the Default of my checkbox. Now I'm trying to add a new button that perhaps to allow to click and "Select all" items in the checkbox gallery but didn't manage to do it. The logic I'm tried is this: 

Collect(Collection, ForAll(Gallery.AllItems,ThisRecord))


@Xinlin wrote:



Default  = If(DataCardValue1.Selected.Value = 'TableDropdownName''.Yes, true,false)




@Xinlin In the above, I don't think the formula is even checking the Collection at all, so you are right this could be the issue. Maybe try something like this instead:



If(!IsBlank(LookUp(Collection,ItemName = DataCardValue1.Selected.Value)),true,false)



 In the above, replace ItemName and DataCardValue1.Selected.Value with something else that makes sense for you if needed.


See if it helps further @Xinlin 

Helpful resources

Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,689)