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 / Trouble setting Galler...
Power Apps
Unanswered

Trouble setting Gallery Default item

(0) ShareShare
ReportReport
Posted on by 35

I'm using a horizontal gallery to simulate a tabbed interface on my app, and it has 3 hardcoded items, such that:

 

Items = 

 [{ID:"General", DisplayName:"General"}, {ID:"D&C",DisplayName:"D&C"}, {ID:"Land", DisplayName:"Land/Midstream"}]

I have display forms below with their visibility property as: 

gal_tab_nav.Selected.Value.ID = "XXX"

 

Therefore, when no selection is made from the gallery, nothing shows up, which is not ideal.

 

I'm having trouble with what to set the Default to so that when the app loads, the General tab is selected. I've tried simply "General", and "[{ID:"General", DisplayName:"General"}]" (with and without square brackets), but I don't know the syntax for an item object when my values are hardcoded.

 

If the declarative syntax is going to be problematic, what would the best imperative syntax be, on say the screen.OnVisible event be?

 

Thanks in advance.

Categories:
I have the same question (0)
  • v-monli-msft Profile Picture
    on at

    Hi @pyee,

     

    Based on my understandings, the Default property expects a record value, and you could try to use first() or the Last() function on the data source.

    Please see below example, the Default would show me the filtered item after I specify the formula.

    large.png

     

    Regards,

    Mona

  • pyee Profile Picture
    35 on at

    Thanks, Mona.

     

    I tried using First(gal_tab_nav.AllItems) since I don't have a data source for these to see if it would pick the first item from that list, but it didn't work. It made the first tab unselectable, even though it gave no errors in the formula bar.

     

    Edit: I've also tried: LookUp(gal_tab_nav.AllItems, Value.ID = "General") to the same effect. The other items are selectable, but the General tab can be clicked, but then gets automatically unselected. It actually produces the opposite effect of what I'd expect there.

  • Gargoolgala Profile Picture
    270 on at

    Pyee,

    did you get a resolution to this?  I have exactly the same issue.

  • pyee Profile Picture
    35 on at

    Not yet. I honestly haven't worked on it much - this was mostly a proof of concept project and I got it working "enough". Seems like a good platform though, just need some of the rough edges knocked off.

  • JC75 Profile Picture
    94 on at

    Same issue - also.

     

    As there isnt a data source as such, you cant use the methods often mentioned. 

     

    The Items source is self created as you have, so how do you specify that one is to be selected as default.

  • Community Power Platform Member Profile Picture
    on at

    I used a Blog from Powerapps to build a tabbed screen and your code looks very similar.  With help from the community forum, I have got this problem sorted.

     

    1.  The first point made to me was that the table definition should not be enclosed in the Square brackets as that stores it as values.  This also fixed the issues referencing values in the Table.

     

    Changing this defaults the screen to the 1st tab after the App is first opened.  This doesn't reset to the 1st tab each subsequent time the screen is opened though.

     

    2.  After some messing around trying to get the Default to work on subsequent views, I tried clearing the Collection holding the table values in the OnHidden property of the screen.

     

    This worked and presumably the table is then rebuilt every time the screen is opened again and the first tab is always selected.

     

    Update:  I found when clicking through from the 2nd tab on this screen to another, the 1st tab was being selected again when the user returned.  In this case I wanted the selection to remain as the second tab.

     

    To overcome this, I created a context variable that is set to true when the Back button is used which will then only Clear my Tabs collection when the back button is used.

     

    Screen OnVisible (and the button from 2nd tabs OnSelect):  UpdateContext({ exitscreen:false })

     

    Screen OnHidden:  If(exitscreen = true,Clear(Tabs))

     

  • Gargoolgala Profile Picture
    270 on at

    This last method does not work as we are not using a collection.  So if we remove the [ brackets we have no items in the gallery 😞

     

    I really wish there was proper documentation and examples for Powerapps

  • Verified answer
    Mike8 Profile Picture
    1,330 on at

    Hello Gargoolgala,

    Please try to switch the Items of your gallery to:

    Table({ID:"General", DisplayName:"General"}, {ID:"D&C",DisplayName:"D&C"}, {ID:"Land", DisplayName:"Land/Midstream"})

    Then you can set the default property to:
    {ID:"General", DisplayName:"General"} or
    First(Table({ID:"General", DisplayName:"General"}, {ID:"D&C",DisplayName:"D&C"}, {ID:"Land", DisplayName:"Land/Midstream"}))

    Then you need to also change

    gal_tab_nav.Selected.Value.ID = "XXX"

    to

    gal_tab_nav.Selected.ID = "XXX"



    Hope this helps.

  • Gargoolgala Profile Picture
    270 on at

    Mike - thanks for the insights.

     

    I have made he adjustments and fixed all the syntax to match etc. so it is working as before - the table option has helped me at least get a default value in without error.

     

    My problem still stands that I enter the screen and it will show my default value but once I navigate to another item it will remember this item if I leave the screen and then return it does not return to the default gallery item.  

    My gallery default is : {ID:"GeneralAspects",DisplayName:"General"}

     

    I did add in the OnVisible of the screen I am entering the GalleryNav.Selected.ID="GeneralAspects" but it still seems to cache the item value.

    I then thought to use Reset(GalleryNav) in the OnVisible but it gives an error stating it expects a resetable control as the input - I suspect this is because a gallery does not ahve a Reset control - not sure why this does not exist 😞

     

    It seems like the default value is being ignored or I am making assumptions on how it works - I would think on the control opening it would be set to the default value.

     

    Any further asssitance is appreciated.

  • Mike8 Profile Picture
    1,330 on at

    Hello Gargoolgala,

    Let's say that the name of the  screen that you have the gallery at, is Screen1.
    You can add at GalleryNav.Default =  If(App.ActiveScreen=Screen1,{ID:"GeneralAspects",DisplayName:"General"}).

    By using the formula above it is like reseting the default value.
    App.ActiveScreen=Screen1 goes true when you are at Screen1 and goes false when you navtigate at an other screen. This way the gallery takes the default value that you need.


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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard