cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stapes
Post Prodigy
Post Prodigy

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
Resident Rockstar
Resident Rockstar

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)

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
Resident Rockstar
Resident Rockstar

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.

View solution in original post

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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,646)