cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stapes
Impactful Individual
Impactful Individual

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
v-xida-msft
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
EricLott
Community Champion
Community Champion

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)
stapes
Impactful Individual
Impactful Individual

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. 

EricLott
Community Champion
Community Champion

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.

v-xida-msft
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.
stapes
Impactful Individual
Impactful Individual

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
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

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

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (2,017)