You are currently viewing PowerApps tips: PowerApps button to select next gallery item
PowerApps button to select next gallery item

PowerApps tips: PowerApps button to select next gallery item

  • Post author:
  • Post category:Power Apps
  • Reading time:5 mins read

This blog post will be the first post of PowerApps tips series, in this series we will learn how to solve some PowerApps problem that faced us, or ow to solve some requirements.

PowerApps button to select next gallery item

We will learn how to select Next item of a gallery or DataSource and display this item in a form while clicking a button.

Problem:

Assuming you have a gallery control named “Gallery1” that displays a collection of items from travel request SharePoint list, you want to get the next item from the gallery and display it in the form in the right, while clicking the next button. So if the current item is not the last item in the gallery, it will get the next item that has an ID greater than the ID of the current item. And if the current item is the last item in the gallery it will display the first item again.

PowerApps button to select next gallery item
PowerApps button to select next gallery item

Solution:

  1. First thing you can create a variable that will contain the first item of the gallery in the OnVisible property of the screen.
Set(CurrentGalleryItem,First(Gallery1.AllItems))
  1. In the Onselect property of next button write this formula that will get the next item in the gallery ,
    The next button is a PowerApps button to select next gallery item.
Set(CurrentGalleryItem,
If(
    CurrentGalleryItem.ID = Last(Gallery1.AllItems).ID,
    First(Gallery1.AllItems),
    First(Filter(Gallery1.AllItems, ID > CurrentGalleryItem.ID))
))

In this formula, “CurrentGalleryItem” represents the currently selected item in the gallery. The formula first checks whether the current item is the last item in the gallery using the “Last” function. If it is, the formula returns the first item in the gallery using the “First” function this will happen when reaching the last item of the gallery or your data source.

If the current item is not the last item in the gallery, the formula uses the “Filter” function to find the first item in the gallery that has an ID greater than the ID of the current item “that will represent the next item to the current selected item”.

  1. Set the item property of the form to be the CurrentGalleryItem to display the next item.

This is how to use PowerApps button to select next gallery item.

See Also
Join us
Need Help
  • Have a related question? Please ask it at deBUG.to Community.

Heba Kamal

Microsoft MVP, MCT, Technical Speaker, Blogger, and Microsoft 365 and Power Platform Consultant.