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 / Select inserted record...
Power Apps
Answered

Select inserted record in gallery when returning from update form

(0) ShareShare
ReportReport
Posted on by 140

Hi All,

 

When I modify a record in an edit form and return to the screen with the gallery that record is still selected. But when I add a record and then return to the gallery the newly record is not selected. That is a bit confusing to the user.

 

How can I make that happen?  I guess something with the Select statement, but I have no clue in which property I should add this code.

Categories:
  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @AGroegelich 

    The reasons for this is that is because the Items property of the form will be Gallery1.Selected and after writing a new record the gallery will still show the last selected record.

    For the suggestion below, I will call your Gallery Gallery1, your Edit/New Form Form1, your data set DataSet1 and the New/Edit screen Screen2

    The are two items that may allow you do do something

    There is a Form property called LastSubmit (so EditForm1.LastSubmit.ID returns the ID of the last item submitted by Form1)

    The gallery has a property called TemplateFill which is the Fill colour of an item in the gallery. This is normally set to something like (ignore the colours below and set your own)

    If(ThisItem.IsSelected,Grey,White)

    So if you set a variable (I will call it vNew) on the Save button of Form1

    If(
     Form1.Mode = FormMode.New,
     Set(vNew,true),
     Set(vNew,false)
    );
    SubmitForm(Form1);
    Back();
    Refresh(DataSet1)

    Then on the TemplateFill of Gallery1

    If(
     vNew,
     If(
     ThisItem.ID = Form1.LastSubmit.ID,
     Grey,
     White
     ),
     If(
     ThisItem.IsSelected,
     Grey,
     White
     )
    )

    The last thing I would do is reset the variable when another record is selected

    Set(vNew,false);
    Navigate(Screen2,ScreenTransition.None)
     

    Please have a try at this and let me know how you go.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

     

     

     

  • AGroegelich Profile Picture
    140 on at

    Hi @WarrenBelz,

     

    Thank you for this elaborate explanation. I tried it and it partially worked. What I first got was that the  newly added was indeed “highlighted” but it was still not selected. What I didn’t mention earlier is that my screen has the gallery on the left pane and a detail form on the right pane. That detail form wasn’t updated and still showed the previous selected record. That is even more confusing.

     

    Second problem that came was that the scroll bar didn’t scroll to the newly added record, so although highlighted the newly added record was not always visible in the gallery. For this problem I found another topic that has a solution:

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Selecting-Position-in-Browse-Gallery/m-p/135381/thread-id/46898 

     

    So in Gallery1.Default I placed this code:

     

     

    If(vNew; First(Filter(DataSet1; ID = Form1.LastSubmit.ID)))

     

     

     

    That positioned the scroll bar in the right position and made that de detail form in the right pane showed the new record. So far so good . Unfortunate there was something odd happening. Although the record in the right pane was showing the correct record, the property Gallery1.Selected appeared not pointing to that record. For example when I click the delete button it removed the first record in the gallery and instead of the highlighted new record.

     

    To summarize: It appears to me that setting Galery1.Default doesn’t set the property Gallery1.Selected. How can I make that happen or did I miss something?

     

    Although your solution didn’t work out completely yet, I think we are halfway there. And you learned me something new how PowerApss works, the awareness of properties like Form.LastSubmit , so thank you once again, much appreciated.

  • AGroegelich Profile Picture
    140 on at

    Hi @WarrenBelz,

    Thank you for your elaborate explanation. Unfortunate it didn’t work out completely. With your code the newly added record was indeed highlighted.But what I didn’t mention earlier is that on my screen there is a gallery on the left pane and on the right pane there is a detail form. So although the newly added record is highlighted, the right pane still showed the record selected before. Thereby it appeared that the scrollbar didn’t scroll to the new record if it wasn’t in the screen (more items then can be fit in the screen).

     

    In another topic I found a solution for this new problem:https://powerusers.microsoft.com/t5/Building-Power-Apps/Selecting-Position-in-Browse-Gallery/m-p/135381/thread-id/46898

     

    So in Gallery1.Default I paced this code:

     

    If(vNew; First(Filter(DataSet1; ID =Form1.LastSubmit.ID)))

     

    This made the right pane with te detail form to be updated and it also adjusted the scroll bar to the highlighted record.

     

    But when I clicked the delete button (without selecting another record) the first record in Gallery1 was removed instead of the record I expected to be deleted (the new one).  The code is:

     

    Remove(DataSet1; Gallery1.Selected)

     

    It was my expectation that setting the Default property of a gallery also would set the property Selected, but apparently not. Or at least not in the way I did. Deleting a not highlighted record is rather confusing.  So the question right now is: Is there a way to set the Selected property as well?

     

    Although not yet the complete solution I am halfway there now. And I am grateful because you made me aware of the LastSubmit property which can be very useful in the future. So thank you once again.

  • AGroegelich Profile Picture
    140 on at

    Hi @WarrenBelz 

     

    Thank you for your elaborate explanation. Unfortunate it didn’t work out completely. With your code the newly added record was indeed highlighted.

     

    But what I didn’t mention earlier is that on my screen there is a gallery on the left pane and on the right pane there is a detail form. So although the newly added record is highlighted, the right pane still showed the record selected before. Thereby it appeared that the scrollbar didn’t scroll to the new record if it wasn’t in the screen (more items then can be fit in the screen).

     

    In another topic I found a solution, 

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Selecting-Position-in-Browse-Gallery/m-p/135381/thread-id/46898

     

    So in Gallery1.Default I placed this code:

    If(vNew; First(Filter(DataSet1; ID =Form1.LastSubmit.ID)))

    This made the right pane with te detail form to be updated and it also adjusted the scroll bar to the highlighted record.

     

    But when I clicked the delete button (without selecting another record) the first record in Gallery1 was removed instead of the record I expected to be deleted (the new one). 

    Remove(DataSet1; Gallery1.Selected)

    It was my expectation that setting the Default property of a gallery also would set the property Selected, but apparently not. Or at least not in the way I did. Deleting a not highlighted record is rather confusing.  So the question right now is: Is there a way to set the Selected property as well?

     

    Although not yet the complete solution I am halfway there now. And I am grateful because you made me aware of the LastSubmit property which can be very useful in the future.

     

  • Verified answer
    WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @AGroegelich ,

    Firstly, my post is actually a workaround to highlight the record, not make it the Selected item (which you can only do by clicking on it), which was all I thought you were after (and I thought the solution to your short question). Yes, I agree that the post below will probably do what you need now that you have elaborated further.

    The other thing you may want to do is to display the new record on the edit form - you can use the same principle in the Items property of the form

    If(
     vNew
     Lookup(
     [MyDataset], 
     ID = Form1.LastSubmit.ID
     ),
     [MyGallery].Selected
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

     

     

  • AGroegelich Profile Picture
    140 on at

    Hi @WarrenBelz,


    This additional code works fine for the detail form on the right pane. For the edit form which is on the next screen I tried the same with a variable instead of Form1.LastSubmit.ID.

     

    The keyword however is


    ... not make it the Selected item (which you can only do by clicking on it)

    This says that I can emulate that the new record is selected, but as long it is not clicked on it, it is not really selected. Then it might be better not to emulate at all as the emulation will bite me sometime unexpected. That will be my solution for this moment, thanks for assisting me in this matter.

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
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard