How to Set Gallery First Item in Power Apps Display Form

Have you ever played with the Power Apps Gallery first value in the Power Apps Display Form control? Not at all?

Well, In this Power Apps tutorial, we will discuss how to Set Gallery First Item in Power Apps Display Form.

I recently had a client request where I needed to set the gallery first item in the Power Apps Display form. I used the steps below to do this in Power Apps.

Also, Read: Power Apps Modern Link Control [Detailed Tutorial]

Set Gallery First Item in Power Apps Display Form

Here, we will see how we can set the Gallery first item in Power Apps Display Form.

Example:

  • A Power Apps Gallery Control (left side image) and a Power Apps Display Form Control (right side image) are seen in the screenshot below. One Power Apps Screen contains both controls.
  • Instead of displaying a blank form when I start or run the app, the Power Apps Display form will show with values for the gallery’s first item.
How to Set Gallery First Item in Power Apps Display Form
How to Set Gallery First Item in Power Apps Display Form
  • Here, I have used a SharePoint list as a Data source connector. The image below represents the SharePoint list (Lead Management) having with various columns like:
    • Last Name = Single line of text
    • First Name = Single line of text
    • Job Title = Single line of text
    • Industry = Choice
    • Company = Single line of text
    • Business Phone = Number and so on
Set Gallery First Value in Power Apps Display Form
Set Gallery First Value in Power Apps Display Form

Now, follow the instructions below to achieve this needs:

  • First, we will create a Power Apps Collection on the App’s OnStart property. And then, create a Context Variable that will hold the default value. This is often done on App start as well.
OnStart = ClearCollect(
    colLeadManagement,
    'Lead Management'
);
Set(
    varDefaultValue,
    First(colLeadManagement)
);

Where,

  1. ClearCollect = Power Apps ClearCollect function eliminates every record from a collection. And then includes a new set of records in the same collection
  2. colLeadManagement = Provide a Collection name
  3. ‘Lead Management’ = Provide SharePoint List name
  4. varDefaultValue = Specify the name of the Context variable
  5. First(colLeadManagement) = This will return the first item from the collection
Power Apps Set Gallery Default item in Display Form 1
Power Apps Set Gallery Default item in Display Form
  • Next, select the Power Apps Display Form and set the variable to its Item property as:
Item = varDefaultValue

Where,

See also  How To Remove Commas From Dataverse Number Field

varDefaultValue = Specify the Context variable name that you have created in the App’s OnStart property

Power Apps Set first item in Display Form
Power Apps Set first item in Display Form
  • Now, select the Next arrow icon (>) from the gallery and apply the code below on its OnSelect property as:
OnSelect = Set(
    varDefaultValue,
    GalLeadDetails.Selected
)

Where,

GalLeadDetails = Gallery control name

Power Apps set gallery first item in Display Form
Power Apps set gallery first item in Display Form
  • That’s what it does in Power Apps Canvas app. Now Save, Publish (Publish this version), and Close the app.
Set Gallery First Item in Power Apps Display Form
Set Gallery First Item in Power Apps Display Form
  • Play the app, and you’ll see that the Power Apps Display form has information on the Gallery’s initial item record.

This is how to set gallery first Item in Power Apps Display form.

Moreover, you may like some more Power Apps and Dataverse tutorials:

In this Power Apps tutorial, we discussed how to Set Gallery First Item in Power Apps Display Form. Also, we saw how to create Power Apps Collection in Power Apps Canvas app.

Happy Reading!

>