web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Cancel Button Selectio...
Power Apps
Answered

Cancel Button Selection In Gallery and return to previous selection

(0) ShareShare
ReportReport
Posted on by 12

Hello All,

 

New to powerapps so please bare with me.

 

I have an Input Screen as below:

InputScreen.PNG

 

The the left is a gallery with sites as buttons, and to the right is a static gallery ( the same list of equipment regardless of what area is selected).

 

We have created a pop up message as suggested here

 

We have wired up to show up in the following scenario:

 

If a user inputs quantities, does not press submit and then selects another area the pop up below will be displayed:

 

PopUp.PNG

 

If they choose continue it clears the text boxes and continues to their next selection. I have this feature working.

 

The issue I am having is with the cancel button.

 

If a user selects cancel I want the following to happen:

1) Do Not clear text boxes - I have this working fine.

2) Revert the previous gallery button selection - This I can't work out.

 

E.g. User starts in Area C1 inputs values BUT does not submit. Instead they choose the area C2. The popup will be displayed and the user chooses to cancel. When they choose cancel, the gallery selection should go back to C1. Currently it just continues to C2  (indicated by the label just to the right of the area buttons)as below:

 

cancelleResult.PNG

 

Is there a way to achieve what I want here?

 

Thank you in advance.

Categories:
I have the same question (0)
  • Carsten_Growth Profile Picture
    Microsoft Employee on at

    Try something like Select(Gallery1; 1; ChildControl1)

    where Gallery1 is your gallery showing the buttons, 1 is the first item(row) and ChildControl1 should be your Button control (name) inside your Gallery1

  • DilshanSS Profile Picture
    12 on at

    Hey @Carsten_Growth  thank you for the quick reply. This is a lot closer to what I want.

    To the OnSelect property of my PopUp window cancel button I added:

    Select(Area,1,Areas). This gets me back to the first item in the gallery. Is there a way the define the last selected instead of hard coding 1?

  • Carsten_Growth Profile Picture
    Microsoft Employee on at

    If you store an Item ID within your Button gallery, you could use it inside a variable with Set(selectedBtn, ThisItem.ID). That way you do have a dynamic value that you can use instead of the hardcoded "1"

  • DilshanSS Profile Picture
    12 on at

    Hi @Carsten_Growth  thanks again for you're reply. 

     

    I have a dimension table: Location (LocationKey, Area, Site)

     

    My gallery: Area

     

    has buttons in it and the text property of the buttons are populated by: ThisItem.Area

     

    For my popUp Cancel button I have added: Select(Area,LocationKey,Areas)

     

    When I run the app cancel just stays on the current selection as if it is not reading the locationKey.

     

    I get the below error on my cancel button:

    the row or columns passed to the select function is outside the bounds of the gallery items

     

    am I missing something here?

     

    Do I somehow need an ID generated for each item on the gallery?

     

    Thanks again

  • Carsten_Growth Profile Picture
    Microsoft Employee on at

     

    has buttons in it and the text property of the buttons are populated by: ThisItem.Area

     

    So does LocationKey contain information, such as 1, 2, 3 ?

    If so you can use LocationKey as your indicator. But you should set a variable by click on the Button. Something like Set(mySelectedItem, ThisItem.LocationKey) which would put mySelectedItem to either 1, 2, or 3 and that could be used then in your Select statement as dynamic variable


     

  • DilshanSS Profile Picture
    12 on at

    Hi @Carsten_Growth 

     

    that is right, LocationKey has integer values (1,2,3,....30)

     

    the OnSelect of my Area button has the below:

    UpdateContext({AreaNameChosen: ThisItem.Area});
    UpdateContext({LocationKey: ThisItem.LocationKey});
    UpdateContext({AreaSelected: true});
    If(And(SubmitSelected = false, AreaSelected = true),UpdateContext({ShowPopUp:true}),UpdateContext({resettext: !resettext}));

     

    I just get the same error: "Row or Column passed to the select function is outside the bounds of the gallery items." Have tried searching this error but not getting much luck. Is there a conversion required. the data type in the sql table is already integer?

     

    Thanks

     

  • Verified answer
    v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi  @DilshanSS ,

     

    You can use the following code to generate a SelectHistory Collection to keep track of the number of rows you select each time, put it to Button.OnSelect in AreaGallery.

    Collect(SelectHistory,Len(First(Split(Concat(ForAll(AreaGallery.AllItems, If(Area = AreaGallery.Selected.Area, 1, 0)), Value & ""), "1")).Result)+1)

    Put the following code on CancelButton.OnSelect property to select the number of rows selected the penultimate time.

    Select(AreaGallery,First(LastN(SelectHistory,2)).Value,AreaButton);Clear(SelectHistory)

    Test Result:

    GIF_55.gif

    Hope this helps,

    Sik

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 387

#2
timl Profile Picture

timl 340 Super User 2026 Season 1

#3
Vish WR Profile Picture

Vish WR 301

Last 30 days Overall leaderboard