cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ryanb1
Frequent Visitor

Remove collection item based on gallery check mark

I have a gallery which collects items when the user checks the check box (copying this tutorial by @vasavib . The code below (which is on the OnCheck property of the checkbox) specifies that if the item is already checked when the users checks it, the item is removed from the collection rather than adding it.

 

My issue is that the item is not being removed from the collection (CheckedItems) in that scenario. What do I need to change? Thanks in advance.

 

Nb. I have used the same names as the tutorial: ChecklistItemsSource and CheckedItems.

 

 

 

If(
    !IsBlank(
        LookUp(
            CheckedItems,
            ID = ThisItem.ID
        )
    ),
    Remove(
        CheckedItems,
        ThisItem
    ),
    Collect(
        CheckedItems,
        ThisItem
    )
)

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ryanb1
Frequent Visitor

Thanks for the suggestion but it didn't work. 

 

In the end I went for the solution described in this video where the appropriate fields are saved into a collection in the OnCheck property; then onselect for a button saves that collection to the datasource. OnUncheck removes the item by finding the first item that matches the filter.

View solution in original post

6 REPLIES 6
Eelman
Super User
Super User

@ryanb1 

Try RemoveIf instead of Remove, like this

 

RemoveIf ( CheckedItems, ID = ThisItem.ID )

 

Also, do all items in CheckedItems have IDs ie they all come from a data source, like SharePoint? Any newly created items that have been entered into the collection but not yet in SP won't have an ID and this could be another possible reason why your code isn't working.

eka24
Super User III
Super User III

All your codes seems in line. Put the same code on OnUncheck. I guess you did it only on oncheck.
ryanb1
Frequent Visitor

Thanks for the idea. For OnCheck I've now changed it to

Collect(CheckedItems,ThisItem)

 and OnUnCheck

Remove(CheckedItems,ThisItem)

It seems too simple but it works. Am I missing anything? 

eka24
Super User III
Super User III

I suggested you put the same code OnUncheck and Oncheck as in the article you cited.
If(!IsBlank(LookUp(CheckedItems,Id = ThisItem.Id)),Remove(CheckedItems,ThisItem),Collect(CheckedItems,ThisItem))
eka24
Super User III
Super User III

If it's resolved kindly Mark as a Solution.
ryanb1
Frequent Visitor

Thanks for the suggestion but it didn't work. 

 

In the end I went for the solution described in this video where the appropriate fields are saved into a collection in the OnCheck property; then onselect for a button saves that collection to the datasource. OnUncheck removes the item by finding the first item that matches the filter.

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,565)