How to Use Power Apps Gallery OnSelect?

This Power Apps tutorial will teach you how to use Power Apps gallery control OnSelect. Then, we will discuss the Power Apps gallery OnSelect navigate Screen and how to get selected gallery record details on a Display form/Edit form using the OnSelct property.

Additionally, we will see how to set a variable in the gallery control using the OnSelct property.

Power Apps Gallery OnSelect

  • When inserting a button into a Power Apps gallery control, the ‘OnSelect’ property of the button input automatically defaults to ‘Select (Parent)’. However, including a button for every row of a vertical gallery is unnecessary.
  • Instead of the button control, we can set Gallery’s OnSelect property to navigate the other screens.
  • Whenever a user clicks or taps the specific gallery item, it will redirect to the next screen to display the selected gallery item details.

Power Apps Gallery OnSelect Navigate Screen

Here, we will discuss how to navigate the details form’s screen using the Power Apps gallery OnSlect property with a simple scenario.

Scenario:

I have a SharePoint Online list named “Employee Registration” and inside this, I have added records based on the different columns, as shown below.

Power Apps Gallery OnSelect Navigate Screen

Now, I want to display these records on the Power Apps gallery, and I would like to get gallery-selected record details in the display form control on the other screen, as in the screenshot below.

powerapps gallery onselect

To work around this, follow the below steps.

1. Select SharePoint Online List [Employee Registration] -> Click on the Integrate dropdown -> Select Power Apps -> Click on the Create an app as shown below.

powerapps gallery onselect navigate screen

2. Then, provide a “Name” for the app -> Click on the Create button.

powerapps gallery control onselect navigate screen

3. Now, we will get a custom Canvas app based on the SharePoint list with three different screens. Such as:

  • BrowseScreen1
  • DetailsScreen1
  • EditScreen1
how to use onselect property in power apps gallery

4. Select a BrowseScreen -> Click on the Gallery control and see the custom OnSelct property code as:

OnSelect = Navigate(
    DetailScreen,
    ScreenTransition.None
)

Where,

  • Navigate() = This function is used to redirect the other screens
  • DetailScreen = Power Apps 2nd Screen
how to use onselect property in power apps gallery control

5. Click on the Preview button and select a specific gallery item, and it will navigate to the browse screen where we will get the selected record details on the display form like below.

how to use powerapps gallery onselect

OR

Similarly, When a user selects any item from the gallery and taps on the button on the browse screen, it will navigate to the edit screen where he/she will get an edit form that will help to display all the details of the selected gallery item from the first screen.

Refer to the below screenshot:

how to use powerapps gallery control onselect

To do so, Select a Browse Screen -> Insert a Button control and set Its OnSelect property as:

OnSelect =  Navigate(
    EditScreen,
    ScreenTransition.None
 )
how to use powerapps gallery onselect property

Now, once the user selects any record from the gallery and then clicks on the button, it will navigate to the edit screens, where we will get the edit form to update the selected gallery record.

how to use a powerapps gallery control onselect

This is how to use the OnSelect property in a Power Apps gallery control.

Power Apps Gallery OnSelect Set Variable

Next, we will see how to use the Power Apps gallery OnSelect set variable with a simple example.

Example:

I have a SharePoint Online list, i.e., [Employee Onboarding] and this list contains the below fields.

power apps gallery onselect set variable

In Power Apps, there is a Gallery control and a Display form. When the user selects any record from the gallery control, it will navigate to the ‘EmployeeDetailsScreen’ where we will get selected record details on the display form as shown below.

power apps gallery control onselect set variable

To achieve the above example, follow the below steps. Such as:

1. Open Power Apps Canvas app -> Connect it to respective SharePoint list [Employee Onboarding] -> Insert a Gallery control and set its Items property -> Select Layout design as “Blank” as in the screenshot below.

Items = 'Employee Onboarding'
gallery control onselect set variable in power apps

2. To display the SharePoint list records, insert Text labels inside the gallery control and set their Text properties like below.

Text = ThisItem.Title

Text = ThisItem.'Employee Name'

Text = ThisItem.Email

Text = ThisItem.Gender.Value

Text = ThisItem.'Employee Department'.Value
how to use power apps gallery onselect set variable

3. Next, select a Gallery control and set its TemplateFill property to the code below.

TemplateFill = If(
    ThisItem.IsSelected,
    Color.LightGreen,
    Color.White
)
how to use power apps gallery control onselect set variable

4. Now, add another screen -> Insert a Display form and set its DataSource property as:

DataSource = 'Employee Onboarding'
how to use gallery onselect set variable in power apps

5. To get the selected gallery record details on a display form, select the gallery control and set its OnSelect property as:

OnSelect = Set(
    varSelectedItem,
    ThisItem
);
Navigate(EmployeeDetailsScreen)

Where,

  • varSelectedItem = Power Apps variable name
  • EmployeeDetailsScreen = Name of the 2nd screen
set variable in power apps gallery using onselect property

6. Next, select the Display form [frm_EmployeeDetails] and set its Item property as:

Item = varSelectedItem
set variable in power apps gallery using onselect

7. Once your app is ready, Save, Publish, and Preview the app. Whenever the user selects any record from the gallery control, it will navigate to the 2nd screen where we will get selected record details on a display form, as in the screenshot below.

set a variable in power apps gallery using onselect property

This is all about the Power Apps gallery OnSelect set variable.

Conclusion

From this Power Apps tutorial, we learned all about the Power Apps gallery control OnSelect. Then, we saw the Power Apps gallery control OnSelect navigate Screen and how to get selected gallery record details on a Display form/Edit form using the OnSelct property.

Last, we also covered how to set a variable in the Power Apps gallery control using the OnSelct property.

You may also like:

>