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 / Gallery initial select...
Power Apps
Answered

Gallery initial selection action

(0) ShareShare
ReportReport
Posted on by 18

I have a gallery and have set all the controls within it as such:

OnSelect = ClearCollect(attaches,ThisItem.Attachments);Select(Parent);ResetForm(Form1);

 

This works well when the user selects an item; the collection variable is populated correctly.  My issue is that this only happens when the user selects the gallery item.  When the app loads, by default the first item in the gallery is selected automatically.  It's not running the ClearCollect() command.  How to I get the initial load of the gallery to also do the ClearCollect() when PowerApps automatically selects an item?  I tried setting the OnSelect of the gallery itself, but this did not resolve the issue.

(this happens not only on load but anytime I filter the gallery)

Categories:
I have the same question (0)
  • NielsD Profile Picture
    24 on at

    Hi,

    A workaround may be to add this in the onvisible of your home screen. 

     

    Hope this helps

     

    Niels

  • toysibuy Profile Picture
    18 on at

    I think this would work on loading the PowerApp initially, but won't solve the issue when filters are applied to the gallery dynamically.

  • Verified answer
    v-yutliu-msft Profile Picture
    on at

    Hi @toysibuy ,

    The reason why when you has not clicked one item, the form still has data is that the gallery.selected is the first item by default, no need you click one item, it will have value by default.

    While the collection that is created by ClearCollect function will not have data by default automatically.

    The ClearCollect function will not perform automatically until you act an action.

    So if you want it has data when you has not clicked one item, you need to set this function to one action that will perform automatically.

    For example: set the app's OnStart,set the screen's OnVisible, set the textinput's OnChange, set the drop down's OnChange, ect.

     

    Could you tell me how do you filter the gallery?

    If you filter the items based on constant value, for example: set the gallery's Items: Filter(....,fieldname="a").

    You could set the screen's OnVisible: 

    ClearCollect(attaches,First(Gallery1.AllItems).Attachments)

    If you filter  the items based on variable, for example a textinput or a drop down.

    Then ,please set the textinput's and drop down's OnChange:

    ClearCollect(attaches,First(Gallery1.AllItems).Attachments)

     

     

     

    Best regards,

  • toysibuy Profile Picture
    18 on at

    That's the workaround piece I was missing.  I didn't have it on the controls that were driving the filter, I only had it in the controls of the Gallery itself.  It seems so obvious now, a real forest for the trees situation. 

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 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard