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 / Gallery selection is l...
Power Apps
Answered

Gallery selection is lost when SubmitForm

(0) ShareShare
ReportReport
Posted on by 10

Hello

 

The Gallery selection is changed when I edit a record and SubmitForm.

 

Please refer to this link

 

https://powerusers.microsoft.com/t5/Building-Power-Apps/Bug-Gallery-with-calculated-values-will-lose-Selected-index-when/m-p/161150#M54252

 

When will this issue be fixed.

 

I tried the following

 

https://powerapps.microsoft.com/de-de/blog/decouplingbrowsegalleryfromforms/

 

It was working before. When the powerapps got updated this is not working as expected. I cannot see the record data in my Display Screen

 

Please suggest how to fix the same

 

Thanks And With Regards

Partha

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

    Hi @kbpartha24 ,

    Do you mean that after you submit an edit form, the gallery's selected item will change?

    Actually, the theory is the same as the issue that you posted.

    Since the gallery's Items is AddColumns(..), after you submit a record, the gallery's selected item will be refreshed.

    To deal with this problem, you just need to save the selected item as a variable. Set your edit form and display form's Item to this variable.

    Even if the gallery's selected item will be refreshed after you submit a record, it will not refresh your variable.

    I've made a similar test for your reference:

    1)set the gallery's OnSelect:

    Set(CurrentSelectItem,ThisItem)

    set the gallery's Default:

    CurrentSelectItem

    2)set the edit form's Item:

    LookUp(datasource,ID=CurrentSelectItem.ID)

    set the display form's Item:

     

    LookUp(datasource,ID=CurrentSelectItem.ID)

     

    //please replace with your data source name, your unique field, I use ID as an example

     

    Then your display form's item will not change after you submit form.

     

     

    Best regards,

  • PhilD Profile Picture
    1,011 on at

    This straight-up does not work! Used precisely the same thing and will not work.

  • PhilD Profile Picture
    1,011 on at

    Tested this just now, the problem has to do with a gallery that has the Search() function as part of its items property. 

     

    This worked fine with a Sort(), Filter() in the items property but the moment I added the Search() part it looses its selection when refreshed no matter what convention is used to define the default item (I tried dozens of variations). It doesn't make a difference where the search function is nested, or if alone or in combination with other functions, as soon as it is introduced, it will not work.

     

    Bottom line, this doesn't work as it is supposed to and its been like this for years. Almost every gallery requires a search function and having the selection randomly jump around is completely jarring and disorienting to the user and is not acceptable. Incredible that a developer is not given consistent and reliable way to control the selection in PowerApps...

  • PhilD Profile Picture
    1,011 on at

    🙄

  • Suggested answer
    FCosta Profile Picture
    4 on at
    @PhilD, we're in 2024 and the same issue persists: the solution provided here (or anywhere else I could find on the Internet) does not work properly if you use the Search() function on the Gallery's Items definition.
     
    I was able to devise a workaround for that - caveat emptor, it works, but it is not super elegant:
    1. Adjust MyGallery.Items so there is a Row number in each record:
      With({Items: Search(... your original gallery items here ...)},
          ForAll(Sequence(CountRows(Items)),
              With({ThisItem: Index(Items, Value)},
                  {ID: ThisItem.ID, Name: ThisItem.Name, ... any other attributes you want to retrieve..., Row: Value}
              )
          )
      )
    2. On MyGallery.OnSelect, put: UpdateContext({SelectedGalleryItem: MyGallery.Selected})
    3. Create a Timer control, and configure it as follows:
      • AutoStart: SelectedGalleryItem.Row <> MyGallery.Selected.Row
      • Duration: 1
      • OnTimerEnd: If(Self.AutoStart, Select(MyGallery, SelectedGalleryItem.Row))
    That's it! At least in my use case, I could not see any important side-effects.
     
    Solution explanation: if you manually select an item in the Gallery, the timer will trigger, but the guard condition in OnTimerEnd prevents it from doing anything (and even if it did, it would have no effect in the Gallery). However, if you change the underlying data listed in the Gallery, the timer also triggers, but the guard condition will evaluate to true, forcing the "proper" item to be re-selected immediately after the Gallery contents are refreshed.
  • LS-03012056-0 Profile Picture
    2 on at
    Fcosta,
     
    your workaround works for me perfectly, thank you so much!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 534

#2
WarrenBelz Profile Picture

WarrenBelz 416 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 306

Last 30 days Overall leaderboard