Best Practices Canvas Apps

OnSelect – how to use for a clickable control in a gallery

A person using a keyboard and a mouse
A person using a keyboard and a mouse

Introduction to OnSelect

OnSelect is one of the most common properties that a lot of the controls have. It defines what needs to happen when a user clicks on a control. To learn more about controls and their properties, click here.

OnSelect within a gallery

The gallery control also has an OnSelect property. Typically, when you add a clickable control, say a button, inside a gallery, its OnSelect is set to Select(Parent) which simply means that clicking on the button will do the same thing as clicking anywhere in the gallery.

In one of the apps I was building recently, for some reason, I had the button's OnSelect set to the same code as that of the gallery. And that code was not working. I kept making changes to the OnSelect of the gallery since I never change the OnSelect of a clickable control inside a gallery. After spending a few hours trying to figure out why my code changes are not making any difference, I figured that since the button had its own code, making changes to the OnSelect of the gallery wasn't doing anything. Every time I clicked on the button, the button's code was getting used.

So if there is a clickable control, say a button, inside a gallery, and the OnSelect of that button is not set to Select(Parent), the code in its OnSelect will take precedence when that control is clicked.

Here is a quick demo:

Demo of OnSelect behavior
Demo of this behavior

Recent articles

  1. How to connect an external barcode scanner with Power Apps<
  2. The modern text input control – what is new about it?
  3. How to add smart offline capabilities in embedded canvas apps

1 thought on “OnSelect – how to use for a clickable control in a gallery”

Leave a Reply