cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Continued Contributor
Continued Contributor

Given a selected record from a gallery, can I do a next or previous?

In one screen, I have a gallery with datasource PhotoImages.

When an image is selected from the gallery, it navigates to the next screen, passing the selected record as SelectedImage.

 

Navigate(Screen4,None,{SelectedImage: Gallery2.Selected})

 

On the next screen, I want to give the user the opportunity to use Next & Previous, rather than having to keep going back & forward.

Can I reset SelectedImage to the Next or Previous item in my datasource?

If so, how?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Hi @stapes ,

Could you please share a bit more about the data structure of your PhotoImages?

Is there a "Row Index" column existed in your PhotoImages data source?

 

Based on the needs that you mentioned, I afraid that there is no direct way to achieve your needs in PowerApps currently. As an available solution, you could consider add a "Row Index" column in your PhotoImages data source as index number, e.g. 1, 2, 3, 4, ...

 

If you want to add a "Row Index" column in your PhotoImages data source, please consider take a try with the following workaround:

Set the OnStart property of App to following:

Clear(PhotoImagesCollection);
ForAll(
       PhotoImages,
       Collect(
               PhotoImagesCollection,
               {
                 RowIndex: CountRows(PhotoImagesCollection) + 1,
                 Column1: PhotoImages[@Column1],
                 Column2: PhotoImages[@Column2],
                 Column3: PhotoImages[@Column3],
                 ...
               }
       )
)

Then set the Items property of the image Gallery  (Gallery2) to following:

PhotoImagesCollection

 

Then modify your Navigation formula as below:

Navigate(Screen4, None);Set(SelectedRowIndex, Gallery2.Selected.RowIndex)

Within your Next screen, you could reference the selected image data from your Gallery2 using the following formula:

LookUp(PhotoImagesCollection, RowIndex = SelectedRowIndex).ImageDataColumn

 

Set the OnSelect property of the "Next" button to following:

Set(SelectedRowIndex, SelectedRowIndex + 1)

Set the DisplayMode property of the "Next" button to following:

If(
   SelectedRowIndex + 1 > Max(PhotoImagesCollection, RowIndex),
   DisplayMode.Disabled,
   DisplayMode.Edit
)

 

Set the OnSelect property of the "Previous" button to following:

Set(SelectedRowIndex, SelectedRowIndex - 1)

Set the DisplayMode property of the "Previous" button to following:

If(
   SelectedRowIndex - 1 < Min(PhotoImagesCollection, RowIndex),
   DisplayMode.Disabled,
   DisplayMode.Edit
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Highlighted
Super User
Super User

Does your data source have incrementing numeric IDs? You could use that to get your gallery data. as in:

Filter(CustomGallerySample,ID = yourSelectedID)

Then you can have a "Previous" and "Next" button that do this:

Previous:
Set(yourSelectedID,yourSelectedID - 1)

Next:
Set(yourSelectedID,yourSelectedID + 1)
Highlighted
Continued Contributor
Continued Contributor

Thanks @EricLott

Unfortunately, the next sequential ID may not be linked to the same parent.

I was hoping I could use Next or Previous within the Datasource already referenced. 

Highlighted

You should still be able to use that sequence ID as long as your data is relational. Can you give a brief rundown of your data structure? For example, if your sequence ID is in another table, but your data is related through a different ID column, you can use Lookup() to find it and increment that.

Highlighted
Community Support
Community Support

Hi @stapes ,

Could you please share a bit more about the data structure of your PhotoImages?

Is there a "Row Index" column existed in your PhotoImages data source?

 

Based on the needs that you mentioned, I afraid that there is no direct way to achieve your needs in PowerApps currently. As an available solution, you could consider add a "Row Index" column in your PhotoImages data source as index number, e.g. 1, 2, 3, 4, ...

 

If you want to add a "Row Index" column in your PhotoImages data source, please consider take a try with the following workaround:

Set the OnStart property of App to following:

Clear(PhotoImagesCollection);
ForAll(
       PhotoImages,
       Collect(
               PhotoImagesCollection,
               {
                 RowIndex: CountRows(PhotoImagesCollection) + 1,
                 Column1: PhotoImages[@Column1],
                 Column2: PhotoImages[@Column2],
                 Column3: PhotoImages[@Column3],
                 ...
               }
       )
)

Then set the Items property of the image Gallery  (Gallery2) to following:

PhotoImagesCollection

 

Then modify your Navigation formula as below:

Navigate(Screen4, None);Set(SelectedRowIndex, Gallery2.Selected.RowIndex)

Within your Next screen, you could reference the selected image data from your Gallery2 using the following formula:

LookUp(PhotoImagesCollection, RowIndex = SelectedRowIndex).ImageDataColumn

 

Set the OnSelect property of the "Next" button to following:

Set(SelectedRowIndex, SelectedRowIndex + 1)

Set the DisplayMode property of the "Next" button to following:

If(
   SelectedRowIndex + 1 > Max(PhotoImagesCollection, RowIndex),
   DisplayMode.Disabled,
   DisplayMode.Edit
)

 

Set the OnSelect property of the "Previous" button to following:

Set(SelectedRowIndex, SelectedRowIndex - 1)

Set the DisplayMode property of the "Previous" button to following:

If(
   SelectedRowIndex - 1 < Min(PhotoImagesCollection, RowIndex),
   DisplayMode.Disabled,
   DisplayMode.Edit
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Continued Contributor
Continued Contributor

Brilliant solution @v-xida-msft - the only think I had to change was

 

UpdateContext({SelectedRowIndex: SelectedRowIndex + 1})

 

instead of

 

Set(SelectedRowIndex, SelectedRowIndex + 1)

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 (8,583)