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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Select a Gallery item ...
Power Apps
Answered

Select a Gallery item on screen visible

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a horizontal gallery on a screen that is acting as a Tab selector.  When the screen is first opened, the screen is blank and the user needs to Click on the Details 'tab' to display the form.

 

I am trying to get the first item in the gallery (Details tab) to be selected when the screen is opened in the OnVisible property but can't get it to work.

 

I have put the following in the event formula:  GalleryNav.Selected.Value.ID = "Details"

 

Can anyone help me with this?

Categories:
I have the same question (0)
  • Sienna Profile Picture
    1,532 on at

    I don't think you can do that in this situation. If I were you I would use collection or static table to store your tab data and then  define default property of your gallery where you tabs are to specify which tab is selected

  • v-monli-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    Like @Sienna said, I also think that your scenario won't work. The first item in Gallery control is the template of all other one. If you set the formula of OnSelect propery, then this formula would applies to all the items in the Gallery. This means that no matter which item you select in this gallery, it will all triggers the OnSelect formula. 

     

    Regards,

    Mona

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I have used a table in the Items property of the gallery to define each tab name and ID as mentioned by Sienna.

     

    [{ID:"Details", DisplayName:"Details"}, {ID:"Comments", DisplayName:"Comments"}, {ID:"Information", DisplayName:"Information"},]

     

    How do I set the Default property?  I have tried using 'ID' or the Displayname but can't get it working.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I found an article that mentions defining the table in the OnVisible property of the screen and then referencing the table name in the Items property of the gallery.  This appears to have worked without setting the Default property of the gallery as the screen now opens with the Details tab selected and showing the form 🙂

     

    Screen OnVisible property = ClearCollect(Tabs,[{ID:"Details", DisplayName:"Details"}, {ID:"Comments", DisplayName:"Comments"}, {ID:"Information", DisplayName:"Information"},])

     

    Gallery Items property = Tabs

     

    I would still like to know how the set the Gallery Default property though.

     

     

  • Verified answer
    Sienna Profile Picture
    1,532 on at

    Ok so you have chosen to use collection for your tabs. Just one fix to your ClearCollect syntax.. Do not use these brackets [ ] because the data will be stored as Values. Replace it with 

     

    ClearCollect(Tabs,{ID:"Details", DisplayName:"Details"}, {ID:"Comments", DisplayName:"Comments"}, {ID:"Information", DisplayName:"Information"})

     

    Now the default property.

    If you want to have select first item of your gallery by default then put this in your default property

     

    First(Tabs)

     

    or last item

     

    Last(Tabs)

     

    or second item

     

    First(Filter(Tabs,ID="Comments"))

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    That was it!  Thanks, it is now working as I would expect 🙂 🙂

     

    I was getting errors when trying the Filter to select the Comments tab but that has fixed that now too. 

     

    Thank you for your continued support on this, I can see others have been having the same issue from my trawling of the internet to find the solution, hopefully it will help them too.

     

  • skylitedave Profile Picture
    652 on at

    I followed this but found some important additional steps to make this work not mentioned here...

     

    1 - I had to use the square brakets when setting up the Collection.  If I only used curly braces then I got errors and it would not work

    2 - I did not need an extra comma at the end of the collection definition.  My collection definition in the OnVisible of he screen looked like this

    ClearCollect(AccountDetailTabs,[{ID:"Tasks", DisplayName:"Tasks"}, {ID:"Notes", DisplayName:"Notes"}, {ID:"Docs", DisplayName:"Docs"},{ID:"AcctContacts", DisplayName:"Contacts", Detail_Account_Contact: false }, {ID:"Opps", DisplayName:"Opps"}])

    3 - I used the Collection ( AccountDetailTAbs) for the items in the Gallery as Suggested - works great

    4 - THIS IS THE KEY - You MUST Clear the Collection in the OnHidden of the screen.  I then set up the collection again to right after I cleared it out so there was no delay on seeing the tabs the next time I open this screen.  I add this to the OnHidden - First I cleared out the collection then I set it up again

     

    ClearCollect(AccountDetailTabs,{});
     
    ClearCollect(AccountDetailTabs,[{ID:"Tasks", DisplayName:"Tasks"}, {ID:"Notes", DisplayName:"Notes"}, {ID:"Docs", DisplayName:"Docs"},{ID:"AcctContacts", DisplayName:"Contacts", Detail_Account_Contact: false }, {ID:"Opps", DisplayName:"Opps"}]);
     
    5. the Default in the Gallery DOES WORK after you clear the collection and then create it again..  so you can use First(), Last() or the First(Filter()) as suggested to set a default ... Default would not work for me until I cleared and reset the collection as shown in step 4...  You could probably just clear the collection in the OnVisoible and then define your collection used for the tabs, but it would slow opening the screen..  better in my mind to do it in the OnHidden so the user does not notice..
     
    Hope this helps someone else stuggling with setting a default for a Tab interface using a horizontal Gallery..  Now I am going to document this so I dont forget how I solved this 🙂

     

  • PytByt Profile Picture
    943 on at

    @Anonymous wrote:

    I have used a table in the Items property of the gallery to define each tab name and ID as mentioned by Sienna.

     

    [{ID:"Details", DisplayName:"Details"}, {ID:"Comments", DisplayName:"Comments"}, {ID:"Information", DisplayName:"Information"},]

     

    How do I set the Default property?  I have tried using 'ID' or the Displayname but can't get it working.


    Hi @Anonymous 

     

    have you solved this one? because i now have the same problem, and i dont use collection. 

     

    thanks,

    pytbyt

  • bouillons Profile Picture
    302 on at

    I have the same basic question, but my gallery is a filter of a sharepoint list based on some other values. When the filter result is changed and there are results, I want to "select" the first result. I haven't found a consistent way to achieve this.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 356 Most Valuable Professional

#2
11manish Profile Picture

11manish 225 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 211

Last 30 days Overall leaderboard