How to get selected value from gallery in Power Apps?

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.

Power Apps get selected items from the gallery
Power Apps get selected items from the gallery

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.

Get selected item value from the Power Apps gallery
Get selected item value from the Power Apps gallery

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)
Get selected item from the Power Apps gallery
Get the selected item from a Power Apps gallery

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.

See also  How to create Power BI report from SharePoint list + Excel

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.
get selected value from gallery in Power Apps
Power Apps get selected items from the gallery to form
  • 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)
Power Apps get selected items from the gallery to edit form
Power Apps get selected items from the gallery to edit form
  • 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.
get selected value from Power Apps gallery
Get a selected item from the gallery to a Power Apps edit form
  • 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.

get selected value from Power Apps gallery control
Get a selected item from the gallery to a PowerApps edit form

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.

Power Apps selected gallery item to edit form
Power Apps selected gallery item to 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:

Power Apps get selected items from the gallery to display form
Power Apps get selected items from the gallery to display form

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.
Power Apps get a selected value from gallery to display form
Power Apps get a selected value from gallery to display form
  • 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.

PowerApps get a selected value from gallery to display form
PowerApps get a selected value from gallery to display form
  • Similarly, update the Items property of the Power Apps display form with the global variable.
Items = varSelectedItem
Get selected gallery items to Power Apps display form
Get selected gallery items to Power Apps display form

On the above screen, we can see that it is displaying all the details from the Power Apps gallery selected item.

See also  Power Automate or Microsoft Flow check day of week

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:

Power Apps get the selected value from a gallery by ID
Power Apps get the selected value from a gallery by ID

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.
PowerApps get the selected value from a gallery by ID
PowerApps get the selected value from a gallery by ID
  • 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)
Get the selected value from a Power Apps gallery by ID
Get the selected value from a Power Apps gallery by ID
  • Add a Power Apps display form to the above screen and connect that display form to the SharePoint list. (I.e., Products list)
How to get the selected value from a Power Apps gallery by ID
How to get the selected value from a Power Apps gallery by ID
  • 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.

Get selected gallery items using ID in Power Apps
Get selected gallery items using ID in Power Apps
  • Similarly, insert the below formula on the display form’s Item property.
Item = LookUp('Products List', ID= VarItemID)
How to get the selected value from a PowerApps gallery by ID
How to get the selected value from a PowerApps gallery by ID

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.

Get a selected value from a Power Apps gallery by ID
Get selected value from a Power Apps gallery by ID

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.

See also  Power Automate length() Function [How to Use]

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.

Power Apps get selected value from a gallery's last item
Power Apps get selected value from a gallery’s last item
  • 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.

How to get selected value from gallery in Power Apps
Get selected value from a Power Apps gallery’s last 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:

>