In this Power Apps Tutorial, we will learn how to get selected values from a gallery in Power Apps.
Recently, we got a requirement to get the value from a Power Apps gallery selected item while working with the canvas app.
Also, we will discuss the below topics based on getting selected values from a Power Apps gallery. Such as:
- Power Apps get a selected value from the gallery to an edit form
- How to get a selected value from the gallery to a display form in Power Apps
- Power Apps get the selected value from a gallery by Id
- Power Apps get selected value from a gallery the last item
First, we’ll look at how to get the value of a Power Apps gallery item that has been selected.
Power Apps get a selected value from a gallery
We’ve created a Power Apps gallery that contains a couple of best-selling books and their authors.
As per the requirement, when a user selects an item from the Power Apps gallery, the selected value is gotten and displayed on the screen. To work with this scenario, the following steps are:
- Add a text label control to the Power Apps screen and place the control next to the gallery.
- Insert the below expression into the Text property of the Power Apps text control.
Text = "You have selected " & Books_gallery.Selected.Author & " - " & Books_gallery.Selected.BookName
Where Books_gallery is the name of the above gallery control.
By default, it is displaying the first selected item value on the Power Apps text label control. To identify the selected value from the Power Apps gallery, insert the below expression on the gallery’s TemplateFill property.
TemplateFill = If(ThisItem.IsSelected, Color.Cornsilk, Color.White)
This is how to get the selected item from the Power Apps gallery.
Power Apps get a selected value from a gallery to an edit form
In this section, we’ll look at how to get a selected value from the Power Apps gallery to an edit form. That is when a user selects an item from the Power Apps gallery control, it will navigate to the edit form and allow the user to edit the selected item within the Power Apps edit form.
To work with this scenario, the following steps are:
- There is a SharePoint list named Projects Management having different types of columns such as single line of text, date, choice, and currency.
- Using the above SharePoint list, we have built a vertical gallery within the Power Apps.
- To identify the selected item within the gallery, insert the below expression on the gallery’s TemplateFill property.
TemplateFill = If(ThisItem.IsSelected, Color.Orange, Color.White)
- Add another screen to the Power Apps and add an edit form to the screen. Connect the edit form to the SharePoint list i.e., Project Management.
- To get the selected item from the Power Apps gallery to an edit form, again insert the below expression on the gallery’s OnSelect property.
OnSelect = Set(
varSelectedItem,
ThisItem
);
Navigate('ProjectManagement Edit Form Screen')
Where ‘varSelectedItem’ is the variable name and ‘ProjectManagement Edit Form Screen’is the name of the Power Apps screen where the edit form is created.
That’s all! Save the app and then open it in preview mode. When an item is selected in the Power Apps gallery, the details of that item are retrieved and displayed within the edit form.
This is how to get the selected item from a gallery to the PowerApps edit form.
Read How to Select First Item in a Power Apps Gallery
Power Apps get a selected value from a gallery to display form
Similarly, here we will see how to get a selected value from the Power Apps gallery to a display form. That means when the user clicks on an item from the Power Apps gallery, the selected items’ details will display on the Power Apps display form as shown below:
We will use the above Power Apps gallery (Project Management System) to get the selected gallery item details in the Power Apps display form; the steps are as follows:
- On the above apps, add a display form to another new Power Apps screen.
- Connect the display form to the SharePoint list data source.
- Insert the below expression on the Power Apps gallery’s OnSelect form.
OnSelect = Set(
varSelectedItem,
ThisItem
);
Navigate(ProjectMangement_Display_Screen)
Where varSelectedItem is the name of the created global variable and ProjectMangement_Display_Screen is the name of the Power Apps screen where the display form is created.
- Similarly, update the Items property of the Power Apps display form with the global variable.
Items = varSelectedItem
On the above screen, we can see that it is displaying all the details from the Power Apps gallery selected item.
This is how to get selected gallery items to Power Apps display form.
Power Apps get the selected value from a gallery by ID
In this section, we’ll look at how to get the value of a gallery item by ID. That is when a user selects an item from a Power Apps gallery, the item is displayed on the display form with all details as shown below:
To work with this scenario, the following steps are:
- We have built a Power Apps vertical gallery using a certain SharePoint list that displays the product’s image, name, and order date.
- To identify the selected item within the Power Apps gallery, insert the following expression on the gallery’s TemplateFill property.
TemplateFill = If(ThisItem.IsSelected, Color.DeepSkyBlue,Color.LightBlue)
- Add a Power Apps display form to the above screen and connect that display form to the SharePoint list. (I.e., Products list)
- To get the selected item details from the Power Apps gallery, insert the below expression on the gallery’s OnSelect property.
OnSelect = Set(
VarItemID,
ThisItem.ID
);
Navigate(Product_FormViewer)
Where Product_FormViewer is the name of the Power Apps display form.
- Similarly, insert the below formula on the display form’s Item property.
Item = LookUp('Products List', ID= VarItemID)
That’s it! Let’s preview the app and select an item from the above Power Apps gallery. We can see that, the details of the selected item will be displayed on the Power Apps display screen.
This is how to get the selected value from a Power Apps gallery by ID.
Power Apps get selected value from a gallery’s last item
In this section, we will see how to get the selected value from a gallery’s last item. That means the last item of the gallery will be automatically displayed on the Power Apps screen.
To implement this, we are going to use the above gallery and the following steps are:
- On the above Power Apps screen, insert the below expression on the gallery’s Default property.
Default = Last(Self.AllItems)
Once the above formula is applied, we can see the last item of the gallery has been selected automatically.
- Add an Image control and place it beside the gallery control.
- Insert the below expression on the Image control’s Image property.
Image = Product_Gallery.Selected.Image
Where Product_Gallery is the name of the Power Apps vertical gallery. The image control will now display the image of the gallery’s last selected item.
This is how to get the selected value from a Power Apps gallery’s last item.
Conclusion
From this Power Apps Tutorial, we learned all about how to get a selected item value from Power Apps gallery based on different scenarios such as:
- Power Apps get a selected value from the gallery
- Power Apps get a selected value from the gallery to an edit form
- Power Apps get a selected value from the gallery to a display form
- Power Apps get the selected value from a gallery by ID
- Power Apps get selected value from a gallery’s last item
You may also like the following Power Apps tutorials:
- Power Apps Set ThisItem Value [With Real Examples]
- How to Highlight the Selected Item within a Power Apps Gallery?
- Display Dataverse Choices in Power Apps Gallery
- How to use Power Apps Gallery Dropdown
- Power Apps Gallery Group By
- How to Get Gallery Item By ID in Power Apps
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.