cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pyee
Advocate III
Advocate III

Trouble setting Gallery Default item

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.

18 REPLIES 18

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.


Mike,

 

thanks again for your assistance.  I got it working slightly different from what you suggested.

 

When I used your option when I navigated to the screen witht he gallery it would briefly appear as the item selected I wanted and would then the form I required to be open when that item is selected would go invisible.

 

My fix was to set the screen to the home screen where I go to select the customers so it would reset back on the home screen but now when I navigate to the screen with the gallry it is "reset" and the correct form is visible 🙂

Anonymous
Not applicable

Nice work Mike, that second method got it working for me, plus I think it is an elegant solution.

I too faced the similer issue on selection default item in gallery. I have followed following steps to resolve this issue

1. gallery should be simple ie.., nested gallery are not supported to select default values. If you have duplicte values use distinct function insted of filtering by using group by and having distinct values.

 

2. Use default function in gallery to select the default tile in gallery and it only supports item type so use filter function with first or last function or use lookup function.

 

 

items:

bdc604
Advocate III
Advocate III

Even when clearing the collection, I cannot get Powerapps to select the first Gallery item in a custom view form by default when closing the view form and selecting a different list item. It fires once, the very first time, then nothing when I go to other list items.

Gallery1.Default = First(Collection1)

I tried Screen1.OnHidden = Clear(Collection1) but that didn’t help.

Any suggestions? Perhaps in SP vs stand-alone apps the custom form is never truly hidden, just collapsed out of view, and OnHidden doesn’t get triggered properly?
Mike8
Memorable Member
Memorable Member

Hello,

Yes, unfortunately there is no property that resets the default value.
You need to have 
Gallery1.Default = If( vBooleanVariable, First(Collection1) ,Last(Collection1) )

Where vBooleanVariable needs to be a boolean value that changes from true to false or false to true when you want to set the default. You can use a variable if it suits you, that changes everytime that you press a button. 
Button1.OnSelect = UpdateContext({vBooleanVariable:!vBooleanVariable})

I tried this and it did not throw an error ,but it does not appear to work 😞

 

Try this in the Default of the Gallery

 

Where the sqare brackets shown below have the items listed in the horizontal Gallery

 

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

 

Maybe this will lead to another approach ...  Seems like it should work...

 

 

 

 

I solved this using the technique mentioned in the thread below but had to add  additional steps

 

Make sure to read my post at the end (SkyliteDave) as it adds some important steps that I had to do to get a default tab value to set

 

Hope this helps someone else

 

https://powerusers.microsoft.com/t5/General-Discussion/Select-a-Gallery-item-on-screen-visible/m-p/8...

 

 

 

 

 

Hi All, 

 

I've been following this thread and I can't seem to make the Table(record1,record2) to work. 

 

I have a tabbed form and I have 2 screens for it, one is for display and one is for edit screen. I was able to set the default by creating a collection of gallery items and then I used "First(CollectionName) on the default property of the gallery. The challenge I have is when the user goes to the Edit Screen and changes tab and then goes back to the Display Screen, it is not selecting the Tab that was selected in the Edit Screen. 

 

I can explain to the user they'll have to deal with it but I don't think that's a good UX design, has anyone solved this?

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,041)