Skip to main content

Notifications

Community site session details

Community site session details

Session Id : HzRVyDJFgb37u7kSjzzHHW
Power Apps - Building Power Apps
Answered

how to clear the selected items in a Gallery

Like (2) ShareShare
ReportReport
Posted on 18 Oct 2019 09:08:38 by 16

I have managed to get my app to work, I now have 3 Galleries "Previous",  "Recent" and CategoriesGallery. Once I clicked on an item in the CategoriesGallery, both "Previous" and "Recent" galleries only show the related items.

Once I click on All Button, it clears all the filters and both Galleries show all contents.

Now I want the All button to also reset the CategoriesGallery so the green color on the Selected item returns to its default color (Blue)

I am looking for something like

"Set(CurrentCategory, Blank()); Reset(CategoriesGallery)"

 

Please advise, its my first powerapps project.

Thanks

Roy

Categories:
  • Suggested answer
    CodeAvenue Profile Picture
    103 on 06 Jan 2025 at 22:44:00
    how to clear the selected items in a Gallery
    Hello @RoyGad,
    A no fail solution that has worked for me is to set the gallery default to a variable example varGallery1
    On the OnVisible of the Screen on which you've the gallery, set that the variable to blank, Set(varGallery1,Blank()); 
    Now, you will want to collect the current selected gallery item into the variable  Set(varGallery1,ThisItem); 
    Then finally, anywhere (this can be a button or icon) you want the OnSelect property to clear the gallery selection, Set(varGallery1, {}); 

    Hope this helps anyone looking for this powerful solution! 

    Cheers
  • downich Profile Picture
    4 on 15 Jun 2022 at 14:34:20
    Re: how to clear the selected items in a Gallery

    Other responses are incorrect in saying an item in the gallery must always be selected!

     

    First set the default record to something that isn't in the gallery* to have it not select anything in the list. Then you can use the Reset function wherever needed.

     

    Example:

    Gallery1 - Default = {ItemHeading:"Blank"}            (where ItemHeading is a field in each gallery record)

    Button somewhere - OnClick = Reset(Gallery1)

     

    *Note: you could use an If statement if for some reason you wanted an actual default record in the list the first time. 

  • Verified answer
    v-yutliu-msft Profile Picture
    on 21 Oct 2019 at 07:40:21
    Re: how to clear the selected items in a Gallery

    Hi @RoyGad ,

    Firstly, you need to kown one important thing.

    The gallery's selected item can not be set to blank.

    It will always be an item.( the first item by default)

    Even if you set the gallery's Default to empty, its selected item will be the first item.

    So you need a little change on your formula.

    I suggest you try this:

    1)set the all button's OnSelect:

    Set(var1,true) //use a variable to justify whether you click this button

    2)set the label's Fill (inside the gallery):

    If(var1,Blue,If(Gallery1.Selected.ID=ThisItem.ID,Green,Blue)) 
    //if you click the button, all the items color becomr blue, or else the item will change based on selection item

     set the label's OnSelect (inside the gallery):

    Set(var1,false) //when you select item in the gallery, the variable value change10218.PNG

     

     

     

    Best regards,

     

  • Pstork1 Profile Picture
    66,091 Most Valuable Professional on 18 Oct 2019 at 12:41:18
    Re: how to clear the selected items in a Gallery

    I think your code should work up to a point.  The problem is that you can't have a gallery with a null selected property.  Galleries always start out with a default selected record.  This is normally the first record in the gallery, but you can change the default to point to any record.  Doing a Reset won't clear the selected property.  It will reset it back to the default, which normally would be the first record.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,745 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard