web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How do I auto-select t...
Power Apps
Unanswered

How do I auto-select the first item in a gallery?

(1) ShareShare
ReportReport
Posted on by 588

This post is tangentially related to this one I made the other day.

 

Essentially, someone gave me a fix which I have worked with to make sure that reference numbers are never doubled up on, however, this fix relies on a gallery (TicketsArchiveGallery) to have the first item 'selected'. This gallery however is 'hidden' on a page of the app the user should never see - it's just there to help me reference the ID number for the new reference number, this means that where my reference number is worked out using the following formula:

 

 

If(TicketsArchiveGallery.Selected.IDStatic >= varID, TicketsArchiveGallery.Selected.IDStatic + 1, varID)

 

 

If I have not 'Selected' record in the gallery it still doubles up reference numbers in certain situations. 

 

My gallery is filtered so it's descending by the IDStatic number:

 

SortByColumns('Tickets Archive', "IDStatic", Descending)

 

 

Is there any way to 'Select.Parent' of the top item in a gallery when another screen is OnVisible (or the app on-start, even)? Is there a better solution to this?

 

 

Thanks!

Categories:
I have the same question (0)
  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @misc 

    Set your Default property to : First(Self.AllItems)

     

    I hope this is helpful for you.

  • RTB_10 Profile Picture
    89 on at

    @RandyHayes  close... but each time I select on another item in the gallery it immediately goes back to the first item.

  • rwittels Profile Picture
    510 on at

    Same issue. Would really help to automatically select the first item in a gallery without it getting stuck on that item.

  • Community Power Platform Member Profile Picture
    on at

    This works for me:  I have a screen with a gallery and a form. The form is, of course, supposed to display the selected gallery item, which I am storing in a variable. So the Item property of the form is set to varSelectedProject. 

     

    On the OnVisible property of the SCREEN, I set varSelectedProject as follows:

    Set(varSelectedProject,First(GalleryProjectFiles.AllItems))


    So now when the user first arrives on the screen, the form is populated with the first item in the gallery, but there is no problem switching to a different gallery item.

  • Community Power Platform Member Profile Picture
    on at

    @Anonymous , will you please elaborate the steps you have taken to solve this problem. Replicated the same but not able to solve this, in my case gallery gets filtered by user login

  • Community Power Platform Member Profile Picture
    on at

    EDIT: I found in some cases, I need to add a ResetForm function to refresh the form and ensure it displays the correct variable. Example:  Set(varSelectedEntry, First(GalleryIssues.AllItems)); ResetForm(FormEdit)

    ****************************

     

    @Anonymous  here's what I did:

     

    I have a screen named Add Products. On the screen I have a gallery and an edit form. The form displays the selected item from the gallery.

    I set the Item property of the Form to varSelectedProject.

     

    formItemPlaybook.PNG

     

    In the gallery, I have a selection icon and the OnSelect property of that icon is set to: Set(varSelectedProject, ThisItem): 

     

    galleryOnSelectPlaybook.PNG

     

    So when the user clicks the icon, ThisItem gets populated on the form. 

     

    To get the first gallery item selected by default, I used the OnVisible property of the screen itself. As soon as the screen loads, I'm setting that varSelectedProject to be the First item in the gallery:

     

     

     

    Set(varSelectedProject,First(GalleryProjectFiles.AllItems))

     

     

     

    onVisiblePlaybookScreen.PNG

     

    Does that help?

     

    P.S. to get the selected item highlighted with a different color, I'm using the TemplateFill property of the gallery:

    templatefill.PNG

  • ClayBurg Profile Picture
    16 on at

    @RTB_10@misc@rwittels I was able to resolve this by creating a variable (e.g. varSelectRecord) and assigning it to a Gallery's (e.g. myGallery) Default property. On loading the page, Set(varSelectRecord, First(myGallery.AllItems). Then set the OnSelect property of myGallery to Set(varSelectRecord, Blank()). This should clear the default record when selecting another record in the gallery. Hope this helps!

  • Community Power Platform Member Profile Picture
    on at

    This answer you gave above worked but  when gallery is loaded  first item is selected according to the code ,while i am trying to select other item for the first time it is not selecting other item , it is selecting other item only after first click it means for second,third and fourth click .
    can you please help me to solve the above issue

     

     

     

    Hey issue got resolved without setting default value to balnk(). i setted onselect property with nothing

  • Community Power Platform Member Profile Picture
    on at

    Can you please help me to solve the issue

  • rwittels Profile Picture
    510 on at

    Using the advice above, use lookup on your default property. Create a variable OnVisible (Use Set or UpdateContext). e.g.

     

    UpdateContext({recordToSelect: Lookup(datasourcename, ID = 15)})

     

    where 15 is the record ID of the record you want selected when the gallery loads. If you store the ID in a variable, then replace 15 with yourvariablename. e.g.

     

    UpdateContext({recordToSelect: Lookup(datasourcename, ID = yourvariablename)})

     

    Set the gallery's default property to your OnVisible variable name (e.g. recordToSelect). When the gallery loads, it will select that record first. Please note that you don't have to use ID. You can use any unique identifier from the data source for your record.

    On your gallery's OnSelect property,  in the first line, change your OnVisible variable name value to CurrentItem. e.g.

     

    UpdateContext({recordToSelect: CurrentItem})

     

    This will ensure that subsequent records that are selected will display the details for the current item.

    Please note that I am using the new Preview of PowerApps (make.preview.powerapps.com), which handles galleries much better.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard