web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Reset Gallery Selectio...
Power Apps
Answered

Reset Gallery Selection Not Working With Patch

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a gallery that displays a list of items for users to select and then use separate controls to edit. When they click on an item, it sets a context variable editVis_ to true, which reveals a group of text inputs to change the details of the item. It also reveals a cancel icon that can be used to exit and unselect the item in the gallery. When they edit an item, it patches the new values to the data source. Once they are done editing the item, I would like them to be able to select the cancel icon to reset the gallery with no items selected.

 

I tried the solutions in this post both by setting the default of the gallery to a context variable defaultSel_ and then adding the line

UpdateContext({defaultSel_: gallery.Selected}); UpdateContext({defaultSel_: {}}); 

to the cancel icon and setting the default of the gallery to {} and using

Reset(gallery)

in the cancel icon.

 

Both of these solutions work until I patch an update to the source list. Once I patch an update to an item, it is set as the default selection no matter what I do. Even if I set up a separate button with the code above, it still resets to select the last item that was patched. Is there something wrong with my code, or is this a bug with PowerApps?

 

Categories:
I have the same question (0)
  • Verified answer
    v-yutliu-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

    Do you mean that if you firstly choose an item, then patch a new item, then click the cancel button, the selected item will not change to blank?

    I've made a similar test and met the same problem like your description.

    However, I found that if I refresh the data source after I patch the new item, this problem will not exist.

    So I think this should be about data refreshing.

    I know it's complicated to refresh the data source every time you patch.

    So I figure out an alternative way to solve this problem.

     

    Maybe you could refer this:

    1)set the arrow button inside the gallery

    OnSelect: 

    Set(var_reset,false)

    2)set the cancel button's OnSelect:

    UpdateContext({defaultSel2_: Gallery2.Selected}); UpdateContext({defaultSel2_: {}});Set(var_reset,true)

    you could also use:

    Reset(Gallery2);Set(var_reset,true)

    3)set the form's Item:

    If(var_reset,defaultSel2_,Gallery2.Selected)

     

    In this way, you could use variable to justify whether you cancel selected item.

    And in this situation, variable will not be affected by the patch function.

     

    1030.PNG

     

    Best regards,

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 416 Most Valuable Professional

#2
11manish Profile Picture

11manish 205 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard