Expressions

Resetting a gallery in Power Apps

There are many use cases where you may want to reset the galleries in your apps. One such example, which we will use in this post, is when we have a gallery of accounts and another gallery of contacts, with the contacts gallery displaying contacts for the selected account. So when you reset the accounts gallery, you would expect nothing to see in the contacts gallery.

Calling the Reset(Gallery_Accounts) function doesn't really reset the accounts gallery. It simply changes the selection to the 1st account. In other words, if prior to calling the Reset function, you had selected the 2nd of the 3rd account, calling the Reset function simply changes Gallery_Accounts.Selected to the first account. Consequently, the contacts gallery displays contacts that are related to the 1st account.

The trick to make this work is to add {} in the Default property of the Accounts gallery. Calling the Reset function now truly resets the Accounts gallery. In other words, calling the Reset(Gallery_Accounts) function sets Gallery_Accounts.Selected to blank and hence, no contacts are displayed in the contacts gallery.

Here is a demo of calling the Reset() function before setting any values in the Default property of the gallery:

Now, let's take a look how adding the {} to the Default property of the gallery changes the gallery's behavior:

To summarize, all that is needed to reset a gallery is the following expression:

Default = {}

Have fun! Get addicted!

2 thoughts on “Resetting a gallery in Power Apps”

Leave a Reply