cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gottijay2000
Advocate II
Advocate II

How to grab the Selected item when the items in the gallery change

I have a gallery whose item property depends on a couple of dropdown selections outside of the gallery. When i click on an item in the gallery i am able to store the selected item in  a variable. But when i change the selection in a dropdown which changes the items in the gallery, there is no way of capturing what the current selected item is, as the gallery does not have an onChange property.

Does anyone have an idea how to get around this?

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Gottijay2000 

The .Selected property of the Gallery will always reflect the selected item.  So, if that is what you are needing, then discard using the variable and instead reference the .Selected property of your gallery.  It will have the selected record.

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
CNT
Super User
Super User

@Gottijay2000 You can have a DataTable with Datasource the same as your Gallery, Items property as YourGallery.Selected and visible as false. Then you can use YourDataTable.Selected to get the item selected in the Gallery wherever you need it. Hope that helps.

RandyHayes
Super User
Super User

@Gottijay2000 

The .Selected property of the Gallery will always reflect the selected item.  So, if that is what you are needing, then discard using the variable and instead reference the .Selected property of your gallery.  It will have the selected record.

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thanks again @RandyHayes , that did the trick. I hope you don't mind if i ask one final question. How do i then ensure that the first item in the gallery is always the selected on. i tried First(gallery2.Allitems) but i couldn't find the selection

RandyHayes
Super User
Super User

@Gottijay2000 

So you want to always have the first item selected??  If so, then you might consider changing the DisplayMode of the Gallery to View.  This will ensure that no one can click on it to change it...the first item will then always be selected.

 

If it is that somewhere in your app you ONLY want to refer to the first item, then yes, First(gallery2.AllItems) will provide the first record of the gallery.  Keep in mind that when referencing the gallery AllItems, it is not only the record data, but also the controls that are in each row that is contained in the table of records.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Changing the Display mode to view may not work in this instance because, the users should still  be able to select any items they want. i went with resetting the the gallery every time there is  a different selection in the dropdowns. Thanks for your help. i appreciate it

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Solution Authors
Top Kudoed Authors
Users online (2,844)