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 Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,499)