cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tapesh
Post Prodigy
Post Prodigy

How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery and add row numbers depending on items in collection?

Hi Experts, 

I have been trying to use the check box to get certain data when the user selects a specific Item and add them to the collection, however, while doing so it adds the records to the collection, but does not remove when a user selects, in fact, it only removes the item from the collection which was last added. 
Please find the screenshot below 

Tapesh_0-1625654309322.png

But the items are unchecked 

Tapesh_1-1625654348571.png

 

when I tried to add another 3 items and remove them only one was removed i.e. last entry,  rest are not removed, any idea why is this happing?

Tapesh_2-1625654426747.png

Final result 

Tapesh_3-1625654536751.png

 

The code onCheck :

 

 

 

Set(
    varSequence,
    CountRows(ExportDataGal.AllItems)
);
Collect(
    ExportData,
    {
        unique_id: varSequence,
        data: ThisItem
    }
);

 

 

 

The code on UnCheck :

 

 

 

Remove(ExportData, 
    {
        unique_id: varSequence,
        data: ThisItem
    }
); 

 

 

 



Could you please help on this if anyone has any idea what's wrong or missing something. 


Thanks a million for taking the time to read and help. 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Eelman @yashag2255 @zmansuri 

Thanks all for the help, support, knowledge, and time. It really means a lot to me, but finally, I got the solution and the result is as below by using a Forall and sequence function. 
OnCheck :

 

 

If ( ThisItem exactin ExportData, Notify("Item already added", NotificationType.Information, 3000),
Collect(
    ExportData, ThisItem
));

 

 

OnUncheck

 

 

Remove(ExportData, ThisItem)

 

On Items property of gallery

 

 

 

ForAll(
        Sequence(CountRows(ExportData),0),
        {
            myRecord:  Last(FirstN( Sort (ExportData ,  ID,Ascending  ),Value +1)),
            rowNumber: Value
        }
    )

 

 

 

 



Tapesh_0-1625743671698.png

 

View solution in original post

11 REPLIES 11
Eelman
Super User
Super User

@Tapesh 

Firstly, I think you need to adjust your OnCheck to this

 

Collect(
ExportData,
{
unique_id: varSequence+1,
data: ThisItem
}
);

 

Then, your OnUncheck could use this

 

RemoveIf( ExportData, unique_id = ThisItem.unique_id)

 

I'm posting this on my iPad so cannot test it but think that should work?

zmansuri
Super User
Super User

Uncheck:

Remove(CollectionName,ThisItem)

Hi @Eelman , 

I tried your way but it did not work , I modified it but same the error, 

Tapesh_0-1625659236970.png

However, I tried this but it's removing all the selections not the just one with the Uncheckmark, 

RemoveIf( ExportData, unique_id exactin ExportData.unique_id);

Hi , @zmansuri

Yeah, this one works fine for normal but I also have come additional data which I'm adding to the collection while on check and Uncheck but seems like it does not work for Uncheck only. 
 Any idea why is it so ?

@Tapesh 

Sounds like some other code is also firing at the same time, what is the full OnUncheck code and do you have any code in the OnSelect of your gallery? If so, post that as well

Hi @Eelman 

Please see the code below I do not have any other code than this one .
OnCheck

Tapesh_0-1625661870082.png

OnUncheck

Tapesh_1-1625661915399.png

 

yashag2255
Dual Super User II
Dual Super User II

Hi @Tapesh 

 

You can use the configuration as below:

 

OnReset or OnVisible -> Clear(CollectionName)

 

OnCheck: Collect(CollectionName, {Identifier: ThisItem.ColumnName, data: ThisItem})

 

OnUncheck: RemoveIf(CollectionName, Identifier= ThisItem.ColumnName)

 

Here, you have to replace ColumnName with the name of column which stores unique values in the gallery.

 

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Hi @yashag2255 

Thanks for the reply but seems like it is same solution which was provided by @Eelman in last reply, sorry to say but it does not work for me as I am using a variable and adding the to collection. could you please help with any other way just in a away where I can create an auto-increment number starting from 0 and end at the last item in the collection.  like Sequnece 0,  1, 2, 3, 4, 5. Would be a great help as I can play around then if I get the auto-increment number whe user add the item to the collection and remove vice-versa.



Thanks

@Tapesh 

What is the Items property of your Gallery ie how is it built? Currently, there isn't a relationship between the Gallery and the Collection which is why you cannot manage the deletion of records. We need to create a relationship to be able to do what you are wanting to do.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

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.

Top Solution Authors
Users online (2,477)