cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Select Item in Gallery OnSelect

When I insert a button into a Gallery, the OnSelect property of the button is automatically set to Select(Parent). I don't want a button in every row of my vertical Gallery. 

 

Instead I want user to click the row of the Gallery, then click a button outside the Gallery to execute OnSelect functions.

 

How do I reference a Gallery row and all its contents when clicked? 

 

Thanks

20 REPLIES 20
Highlighted

A few options to fix the issues that you have:

  • I'm having trouble with the Form showing the selected Row. 
    • So far I've tried setting the Form Item Property to the three options below, but no success:
      • Filter(
            'Sharepoint List',
            ID = gallery.Selected.ID)
        • Error: This expects Record values but produces incompatible Table values.

Try using a LookUp call instead of Filter - that will return the item itself, instead of a list of items (with 1 element).

  • gallery.Selected
    • No Error, but all Form fields are blank. 

That should work - the gallery selection is an object, and if the Items property of the gallery has the same data source as the DataSource property of the form, then it should work. Another thing you can try to do is to call EditForm(FormName) prior to the Navigate call.

Highlighted

I was able to: 

 

  • Display a Gallery of Sharepoint items
  • User clicks a Gallery item to select it
  • Button click (outside of Gallery) opens a Form with the partially completed record loaded

I know it doesn't sound like much, but that was an intense challenge! Thank you @CarlosFigueira and @Shanescows for the valuable insights. Below is the breakdown for anyone else needing this type of functionality. 

 

Gallery

  • Name: gallery
  • DataSource: sharepointList
  • Items: Filter however you like. In my case I only want to show items with a certain staus.
    • Filter( 
              sharepointList,
              status = "not started")
  • OnSelect: Creates a variable with the entire sharepoint item stored as a record.
    • Set(
          varSelectedItem, 
          gallery.Selected
          )
    • Important note: Even though I'm building a single screen app here (no Navigation), UpdateContext did NOT work when setting the varSelectedItem variable. I HAD to use Set. I think it has something to do with Visibility. 

Button: Outside of gallery

  • Name: button
  • OnSelect:
    • EditForm(
          form
      );
      //Makes form visible//
      UpdateContext(
          {varFormVisible: true}

Form

  • Name: form
  • DataSource: sharepointList
  • Items: varSelectedItem
Highlighted

use a transparent rectangle in your gallery, set it to be the size of your gallery item, set the rectagle to be in front of all other object.  On Select of the Rectagle, navigate to your new, edit or read only screen.  No need for an ugly button in your gallery and your can delete the default ugly right arrow.  In the attached example we use the transparent rectagle and the touch agent and the red heart sits on top of that so uses can remove the items from their favorites list.  

PowerApps.PNG

Highlighted

Hi @CarlosFigueira 

In this thread thats 2 yrs old, you had mentioned...

You can also access an arbitrary row in the gallery (by index) using the AllItems property of the gallery, and the FirstN/Last functions to retrieve the item at the desired index.

Could you please share the formula how to do this. I have a gallery that has a collection as the DataSource. How do I select a particular record in this gallery?

Highlighted

You can use the expression like this:

Last(FirstN(Gallery.AllItems, <index>)

Notice that if you have a collection that is used as the items in the gallery you should use it directly (as accessing Gallery.AllItems can be expensive).

Last(FirstN(<collection>, <index>))

Hope this helps! 

Highlighted

Hi @CarlosFigueira 

Thanks for u'r reply. My collection has a unique field PersonID. How do I get the<index> from that? Could you also please explain what Last(FirstN(...  is doing? Could I set this formula in the Default property of the Gallery?

Thanks a lot

Highlighted

The expression

Last(FirstN(<table>, <index>))

Returns the item at <index> from the table. Imagine that your table contains the following elements:

[
    { Value: 1, Square: 1, Cube 1 },
    { Value: 2, Square: 4, Cube 1 },
    { Value: 3, Square: 9, Cube 27 },
    { Value: 4, Square: 16, Cube 64 },
    { Value: 5, Square: 25, Cube 125 }
]

The expression

FirstN(<table>, 3)

 Returns another table with the first 3 elements of the original table:

[
    { Value: 1, Square: 1, Cube 1 },
    { Value: 2, Square: 4, Cube 1 },
    { Value: 3, Square: 9, Cube 27 }
]

And taking the last of that elements will give you the 3rd element of the original table.

 

So that is how you would retrieve a particular element given its index... If you want to retrieve the index of a particular element (i.e., the inverse of the previous operation), we don't have anything direct that does that, but there is a new Sequence function (currently in the Preview region, likely to reach all regions in 1-2 weeks, I think) that can help. Here's an example for the table below, if you wanted to know the index for the record whose Cube is 64:

LookUp(
    AddColumns(
        Sequence(CountRows(<table>)),
        "Item",
        Last(FirstN(<table>, Value))),
    Item.Cube = 64,
    Value)

What the expression above is doing (in the Sequence function - its documentation should be live when it reaches all the PROD regions) is first creating a table with a single column (Value) and records with values 1, 2, 3, ... up to the number of elements in the table. It then adds a column to this new table (Item) whose value is the corresponding record from the original table. Finally, it searches for the Value (index) where the condition is met.

 

Now, back to your last question - if you have a unique field (PersonID), you don't need to know the index, you can use a LookUp expression to set it directly as the Default property of the gallery. If the Items property of the gallery is set to <table>, then you can use this expression to set a specific value as the default property:

LookUp(<table>, PersonID = <the value you want as the default>)

Hope this helps!

Highlighted

Hi @CarlosFigueira 

Thanks a lot for the detailed explanation. The reason I asked you these questions in the first place was because I am getting a strange error in the LookUp function in the default property of the Gallery.

Error MessageError Message

 I am using exactly the same LookUp formula you had mentioned.

LookUp([@People],'Person ID'=frmPeople.LastSubmit.'Person ID')

Here frmPeople is an EditForm which points to the Selected Item of the Gallery. Could you please shed more light into this error and give ideas to solve this.

Thanks a lot.

Highlighted

Hi @CarlosFigueira 

Any updates on the Sequence function? When we will get it?

Thanks a lot.

Highlighted

It's already in the Preview/First Release region (if you create an environment in that region you'll see it). It's scheduled to be deployed to all regions by early to mid next week, so depending on the region of your environment you may get it sooner.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (7,930)