cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DBSTJC
Regular Visitor

Locate and uncheck a gallery item from another control

Hi.  I need a little assistance with galleries.  I have 2 galleries (gallery 1 & 2 in the attached) that contain the same list of items.  Selecting an item from either gallery will add that item to a collection. The third gallery shows the contents of the collection.  The fourth gallery shows a distinct list of items in the collection.  You can see in gallery 3 that apples and cherries appear twice.  This is intentional.  If I click the trash can in gallery 4 for Apples I want to programmatically uncheck the corresponding item in gallery 1 & 2.  This is were I'm stuck.  I'm not sure how to locate the item in the gallery and uncheck the checkbox.

 

The scenario probably would not appear in the real world but I would like to know for my own education.

 

Any thoughts?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@DBSTJC 

Normally I would not suggest a collection for all of this as the Gallery already serves as a collection.  However, in this scenario, you must take "snapshots" of the checkboxes as you go or else you will end up in a circular situation and get an error for that.

 

So, essentially, for the checkboxes in Gallery1, 

 OnCheck: Collect(colList1, {Value: ThisItem.Value})

 OnUncheck: Remove(colList1, {Value: ThisItem.Value})

 Default: ThisItem.Value in colList1

Same thing on the checkboxes in gallery 2, except change the colList1 to colList2.

Then the Items property on Gallery3:

Filter(
    Ungroup(
        Table({Items: colList1},
            {Items: colList2}
        ),
        "Items"
    ),
    !IsBlank(Value)
)

 Gallery4 Items:

Distinct(Gallery3.AllItems, Value)

 

On the OnSelect of the trash icon:

RemoveIf(colList1, Value=ThisItem.Result); RemoveIf(colList2, Value=ThisItem.Result)

 

Result:

DBSTJC.gif

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

3 REPLIES 3
RandyHayes
Super User
Super User

@DBSTJC 

Normally I would not suggest a collection for all of this as the Gallery already serves as a collection.  However, in this scenario, you must take "snapshots" of the checkboxes as you go or else you will end up in a circular situation and get an error for that.

 

So, essentially, for the checkboxes in Gallery1, 

 OnCheck: Collect(colList1, {Value: ThisItem.Value})

 OnUncheck: Remove(colList1, {Value: ThisItem.Value})

 Default: ThisItem.Value in colList1

Same thing on the checkboxes in gallery 2, except change the colList1 to colList2.

Then the Items property on Gallery3:

Filter(
    Ungroup(
        Table({Items: colList1},
            {Items: colList2}
        ),
        "Items"
    ),
    !IsBlank(Value)
)

 Gallery4 Items:

Distinct(Gallery3.AllItems, Value)

 

On the OnSelect of the trash icon:

RemoveIf(colList1, Value=ThisItem.Result); RemoveIf(colList2, Value=ThisItem.Result)

 

Result:

DBSTJC.gif

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
DBSTJC
Regular Visitor

Hi Randy,

 

This was exactly what I was needing.  Thank you.  

 

But now I have another question.  You mentioned you would not use a collection for all of this as the Gallery already serves as a collection.  I believe that would be more straight forward and could eliminate the need for Gallery 3.  How would that change the above example?

 

Thanks,

 

Terry

RandyHayes
Super User
Super User

@DBSTJC 

Yes, so just get rid of Gallery 3 and set the Items of Gallery 4 to:

Distinct(
  Filter(
    Ungroup(
        Table({Items: colList1},
            {Items: colList2}
        ),
        "Items"
    ),
    !IsBlank(Value)
  ), 
Value)

That gets rid of Gallery 3.

 

As for the initial checkbox gathering, the collections are needed there as you essentially need an in-memory database to be able to add and remove records...that IS what a collection is - and a proper use for it as well.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (2,450)