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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Select Gallery Item af...
Power Apps
Answered

Select Gallery Item after Remove

(0) ShareShare
ReportReport
Posted on by 39
Hey all,
 
I have a gallery with the following code set for the properties,
 
OnSelect : 
UpdateContext({ currentItem: ThisItem });
 
Default:
currentItem
 
The screen has a form on it whose Item property is set to currentItem.
 
I also have an icon on the screen that will remove the currentItem in the OnSelect handler using this code:
Remove(dataSource,currentItem);
UpdateContext({currentItem:First(qnGallery.AllItems)});
 
 
My problem is that after the calling the Remove method, the Gallery ends up with no selected item, and the form retains the values of the removed item.
 
Can someone see what I am missing and/or how to correct this so the first gallery item will be selected after removing an item?
Thanks
Kevin
Categories:
I have the same question (0)
  • Mark Nanneman Profile Picture
    991 Moderator on at
    What is the datasource of  your gallery?  I'm assuming it's the same source you're removing the item from but just want to check. 
     
    Also, what kind of datasource is it?  SharePoint?  Dataverse?  A custom collection of some sort?

    I just tried emulating what you're doing with a Canvas App gallery using sample data from a Dataverse Contacts table, and it seems to work fine.
     

     
  • Suggested answer
    WarrenBelz Profile Picture
    153,731 Most Valuable Professional on at
    This can be tricky with the Default. Instead of using the the Variable, simply make the Default the First of your Items code - example if your Items was
    Filter(
       DataSource,
       Status.Value = "Current"
    )
    then the Default of the Gallery would be
    First(
       Filter(
          DataSource,
          Status.Value = "Current"
       )
    )
    You can then simply delete the item and reset the gallery
    Remove(DataSource,ThisItem);
    Reset(Parent)
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    Buy me a coffee
  • KevinBod Profile Picture
    39 on at
    Thank you for your response.
     
    Yes, the data source in the remove statement is the same as in the Gallery Items property. It is a SharePoint list.
    Kevin
  • KevinBod Profile Picture
    39 on at
    Thank you for your reply WarrenBelz.
     
    I have made the change as you suggested, and it works great unless I am trying the remove the first item in the gallery. If I try removing the first item, I get the same response as before: the item gets removed from the SharePoint list, but the information in the form does not update (it still shows the item that was removed), and the gallery has no selected item.
     
    FWIW, this is the Gallery Item code (for testing, the search text is empty):
    SortByColumns(
            Search(
                datasource,
                qnSearchInput.Text,
                'NCR Number','Supplier Name','Supplier Number',Material      
            ),
        "ID",
        SortOrder.Descending
    )
     
    Thank you again for your time.
    Kevin
  • Verified answer
    WarrenBelz Profile Picture
    153,731 Most Valuable Professional on at
    What I posted is a workaround for something that is a bit unusual and should technically work. I have now created a model based on what I posted and it works fine when the first item is deleted. What I suspect is the Item of the Form is not what it needs to be. Assuming you are using SharePoint, try
    LookUp(
       DataSource,
       ID = GalleryName.Selected.ID
    )
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 301 Super User 2026 Season 1

#2
WarrenBelz Profile Picture

WarrenBelz 297 Most Valuable Professional

#3
VASANTH KUMAR BALMADI Profile Picture

VASANTH KUMAR BALMADI 195

Last 30 days Overall leaderboard