cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
audrieg
Power Automate
Power Automate

How Can I Clear a Gallery Selection

I love using the gallery selection to get values that I will use in my submit and/or patch functions. However, when I come back to the screen after performing my actions, I'd like to screen to start fresh without any selections.

 

How, do I clear the gallery selected items onvisible for my screen?

 

Use Case:

Gallery1 is full of items from data source on screen1

Text1.Text is defaulted to Gallery1.Selected.Value.Field

After the first click on Gallery1 Text1.Text shows the correct value

I submit, and navigate to confirmation screen

I return to screen1

but I want Text1.Text to be blank again

....so I would like to know how to clear the gallery selection

 

Thank you in advance for your help!

15 REPLIES 15

Hi,

 

did you find the solution? I have this same problem 😞

 

Cheers

Sebastian

Hi everyone,

 

I realize this will not an option for all scenarios, but the most effective way that we have found for the gallery to 'forget' which item was selected, or even that something was selected is, by clearing the data source Smiley Surprised

 

a) Set gallery.default = {}

b) If gallery.items contains a collection, clear the collection on form onvisible or from whatever is calling the form. If you use ClearCollect, this will not reset the gallery, because it doesn't seem to put the gallery in a state where it doesn't contain any items at any stage, which is what causes the gallery to reset the selection.

 

I haven't tried the above with other datasources, to possibly set the gallery.items property to something like [{ }] during certain triggers, but this might be worth trying.

 

In what world is that "Easy?"

 

There should not have to be a workaround for every little piece of basic functionality but it seems that is what powerapps make us do. Having to use Context variables to do anything useful drives me nuts.

 

This is broken! ... It should be fixed!

Mike8
Memorable Member
Memorable Member

Hello,@JeremyDIV I agree with you. Some things should be simpler.
@DavesTechTips is right. You need to "refresh" the items, but there no need to clear the collection.

If you need to refresh the gallery in order not to have selected item you can do these:

Solution1: If you need only one button that triggers the refresh,

Gallery1.Default = {}                                                                    (as Dawidvh said)
Gallery1.Items = If(!Button1.Pressed,Collection1)                       (notice the !   It's !Button1.Pressed)
This way whenever Button1 is pressed it goes, false true, and it's like the Items in the gallery are reseting

Solution 2 that is more generic,

Gallery1.Default = vDefaultGallery 
and whenever you want to refresh the selection of the gallery, in our case Button1, add this:
Button1.OnSelect = UpdateContext({vDefaultGallery :Blank()});UpdateContext({vDefaultGallery :{}})

I

mdevaney
Super User III
Super User III

@audrieg 
Set the Default property of the gallery to this code

Defaults('Your Datasource Name')


Then put this code in the OnSelect property of a button.

Reset(Gallery1)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

PowerAddict
Super User II
Super User II

@audrieg just setting the Default of the gallery to {} and using the Reset function is good enough. Here is a quick blog on this: https://thepoweraddict.com/resetting-a-gallery-in-power-apps/

 

---
If you like this reply, please give kudos (Thumbs Up). And if this solves your problem, please mark this reply as a solution by selecting Accept as Solution. This makes it easier for others to find answers to similar questions. 

 

Thanks!

Hardit Bhatia

Microsoft Business Applications MVP

Microsoft Certified Trainer MCT

Blog | Twitter | LinkedIn | Facebook | YouTube  |  Email

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.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (850)