cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AnthonyPhan
Level 8

Nested gallery problem

Hi All,

I have produced an app with a nested gallery.

 

Gallery 1 points to 'collection A'  (a collection names) and contains Gallery 2 and a textbox1 showing the name.
Gallery 2 is nested inside Gallery 1 and contains a textbox2
The contents of textbox2 is equal to textbox1.Text and hence shoudl show the name. Everythign is working ok. 

 

If i add a new name to the collection the gallery will add another iteam (as expected), however the name shown in Textbox2 will equal the name shown in the first iteam in the gallery. the expected behavious would be textbox2.text would equal the new name added to the collection.  

 

Is there a way I can refresh the gallery to show the correct fields?

1 ACCEPTED SOLUTION

Accepted Solutions
mr-dang
Level 10

Re: Nested gallery problem

If I understand correctly:

  • Textbox2.Text is showing the Text for the first item in Gallery1 for all items rather than the respective Textbox1.Text.

 

I've had this situation before and I think it is following the expected behavior. I intuit that what PowerApps is thinking is that the control itself is stored in the first row of Gallery1, even though it is replicated for subsequent rows of the gallery. 

 

I have two solutions, but they are roundabout. I think there could be an easier way if there is something in common between the Items property of the two galleries:

  1. Add a helper column to Gallery2 to show the respective record
  2. Change Textbox2.Text to reference a LookUp to the respective record

 

Solution 1:

Change Gallery2.Items to:

AddColumns(youroriginalitems,"helpercolumn",Textbox1.Text)

 

This means, "In Gallery2, show the items you originally wanted to show, but add a helper column for the respective Textbox1.Text."

 

Then change Textbox2.Text to:

ThisItem.helpercolumn

 

This should work because Gallery2's Items property can correctly reference Textbox1 since they are on the same level. Textbox2 has problems referencing Textbox1 because they are at different levels.

 

 

Solution2:

Change Textbox2.Text to:

LookUp(Gallery1.AllItems,PrimaryKey=ThisItem.PrimaryKey,Textbox1.Text)

or

First(Filter(Gallery1.AllItems,PrimaryKey=ThisItem.PrimaryKey)).Textbox1.Text

This means, "Look up the respective record within all the items in Gallery1 that matches the primary key (or whatever unique identifier you use), select the first one and return its respective value in Textbox1.Text." Note that this does mean you need to have something matching between Gallery1 and Gallery2.

 

The idea is that Textbox2 is now going to try to identify the correct value for Textbox1 using a LookUp.

 

Let me know how this works out.

Microsoft Employee
@8bitclassroom

View solution in original post

2 REPLIES 2
mr-dang
Level 10

Re: Nested gallery problem

If I understand correctly:

  • Textbox2.Text is showing the Text for the first item in Gallery1 for all items rather than the respective Textbox1.Text.

 

I've had this situation before and I think it is following the expected behavior. I intuit that what PowerApps is thinking is that the control itself is stored in the first row of Gallery1, even though it is replicated for subsequent rows of the gallery. 

 

I have two solutions, but they are roundabout. I think there could be an easier way if there is something in common between the Items property of the two galleries:

  1. Add a helper column to Gallery2 to show the respective record
  2. Change Textbox2.Text to reference a LookUp to the respective record

 

Solution 1:

Change Gallery2.Items to:

AddColumns(youroriginalitems,"helpercolumn",Textbox1.Text)

 

This means, "In Gallery2, show the items you originally wanted to show, but add a helper column for the respective Textbox1.Text."

 

Then change Textbox2.Text to:

ThisItem.helpercolumn

 

This should work because Gallery2's Items property can correctly reference Textbox1 since they are on the same level. Textbox2 has problems referencing Textbox1 because they are at different levels.

 

 

Solution2:

Change Textbox2.Text to:

LookUp(Gallery1.AllItems,PrimaryKey=ThisItem.PrimaryKey,Textbox1.Text)

or

First(Filter(Gallery1.AllItems,PrimaryKey=ThisItem.PrimaryKey)).Textbox1.Text

This means, "Look up the respective record within all the items in Gallery1 that matches the primary key (or whatever unique identifier you use), select the first one and return its respective value in Textbox1.Text." Note that this does mean you need to have something matching between Gallery1 and Gallery2.

 

The idea is that Textbox2 is now going to try to identify the correct value for Textbox1 using a LookUp.

 

Let me know how this works out.

Microsoft Employee
@8bitclassroom

View solution in original post

AnthonyPhan
Level 8

Re: Nested gallery problem

Hi Mr-Dang Thank you for your response. I was able to solve the problem using solution 1. In my opinion this is the more elegant solution. As for your comment about this following the expected behaviour, I would disagree. If a row already exists within the collection prior to running the app it will reference the correct text box, however if it is added later (during run time) it reference the first row of the gallery.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,612)