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 / Conditional selection ...
Power Apps
Answered

Conditional selection of gallery default item

(0) ShareShare
ReportReport
Posted on by 9

I am building a Canvas App on top of a SharePoint List. The app is a "sidebar" layout in which the user selects an item from the gallery in the sidebar and is then able to view and edit a number of fields in that item via a form in the main view.

The items in the gallery are filtered based in part on the value the user has selected in a dropdown menu.

A simplified version of the gallery's Items property looks like this (note that the actual code is more complicated and also involves sorting and ordering - I can provide more details if helpful but didn't think they were relevant to problem):

 

Switch(

gallerydropdown.SelectedText.Value,

"X",

Filter(DataSource, Field1.Value = "a", Field2.Value = "b"),

"Y",

Filter(DataSource, Field1.Value = "b", Field2.Value = "a"),

"Z")

 

The form's Item property is simply set as gallery.Selected.

 

The issue I have is that when a user makes and saves changes to an item via the form, the gallery resets and the first item in the gallery is selected by default. Obviously the form data displayed then changes as well. I would like the previously selected item to remain selected, **providing that it is still present in the gallery** (i.e., it still meets the filter conditions for the selected gallerydropdown option). If the item is no longer present in the gallery, I would like the default selected item to revert to the first item (i.e., the "normal" behaviour for a gallery).

 

Example behaviour I am after:

Case 1: A user selects choice "X" from the gallerydropdown. Two items are displayed in the gallery - Item 1 which is displayed first, and Item 2 displayed second. User selects Item 2 and makes changes to some fields, but Field1 and Field2 remain unchanged (i.e., the item continues to satisfy the filter conditions for the gallery when "X" is selected). When User submits these changes I would like Item 2 to continue to be selected in the gallery (rather than the selection defaulting back to Item 1).

 

Case 2: As above in terms of the items in the gallery, but this time the User changes the value of Field1 for Item 2 to "c". When this change is saved, Item 2 will no longer be displayed in the gallery while "X" is selected in gallerydropdown (which is currently the case). In this case, I would like the gallery selection to default to Item 1.

Categories:
I have the same question (0)
  • Verified answer
    v-jefferni Profile Picture
    on at

    Hi @LL_Yoor ,

     

    Please try below method:

    1. OnSelect of the Gallery, set a variable for the selected item:

    Set(varSelected, ThisItem.ID)

     

    2. Set Default of the Gallery and Item of the form to:

    LookUp(DataSource,ID = varSelected)

     

    Hope this helps.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • LL_Yoor Profile Picture
    9 on at

    Thanks @v-jefferni. I don't think this handles Case 2 from my example (the item continues to be selected even if it is no longer present in the gallery) but I can work around that in other ways I think.

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard