cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Reset Gallery and change displayMode

Good Evening All,

 

I'm hoping someone might be able to shed some light on an issue I'm having with the Gallery control.  The issue is that when the screen loads I set a variable to a record and have that as the default for the Gallery and another variable to change the displayMode of the Gallery to either Edit or View mode.  


Screen1.OnVisible: UpdateContext({defaultRecord: LookUp(collection, Id = 2 ), editMode: false })
Gallery1.DisplayMode = If(editMode, DisplayMode.Edit, DisplayMode.View)
Gallery1.Default = defaultRecord
EditIcon.OnSelect = UpdateContext({editMode: true})

Then i have a cancel icon that reset the gallery back to the defaultRecord and put the Gallery back into DisplayMode but the issue is that gallery doesn't change back to the defaultRecord the gallery stays on the record the user has selected
Cancel.OnSelect = UpdateContext({defaultGalleryRecord: {}}); UpdateContext({defaultGalleryRecord: LookUp(collection, ID = 2) }); UpdateContext({editMode: false})

If I add a Timer to wait 100ms and then update the editMode to false it works fine,  the gallery changes back to the defaultRecord.   

Is there a way to change a gallery back to the default Record and change the displayMode to view only without including a timer?

 

Thanks all

1 ACCEPTED SOLUTION

Accepted Solutions

@stefen 

Yeah, it's a little odd what you are trying to accomplish with the Gallery.  The Gallery DisplayMode needs to be in Edit mode to respond to any changes (as you've seen from your timer attempt).

Let's go another way...

I don't know what controls you have in your Gallery or how they respond to editMode - are they set to "respond" to editMode, or are they set to Parent.DisplayMode?

If they are Parent.DisplayMode, then change them to editMode.

Then, adjust your control formulas as follows:

 

Gallery1 -

    Default :  Lookup(colGallery, ID=2)

    DisplayMode : Edit

    Selectable : If(editMode, true, false)

 

Edit - 

   OnSelect : UpdateContext({editMode:true})

 

Cancel - 

   OnSelect : UpdateContext({editMode:false}) ; Reset(Gallery1)

 

See how that fairs out for you.

What we did was stop trying to make DisplayMode keep us from doing things in the Gallery and instead made the controls in the Template respond to if they are editable or not.  Then, for the Gallery, we just forced the Selectable ability on or off depending on edit mode.

 

I believe that will give you what you are looking for - although a slightly different way.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

6 REPLIES 6
Super User III
Super User III

@stefen 

I'm not entirely following how you have your screen set up.  You mention that users have selected another Gallery item and you want it to return to the default.  However, you have the gallery in view only mode (non-selectable) until they hit edit.  

So, I'm assuming that once they are in editMode, they are able to then select other items, and then ultimately, you want the Gallery to return to the default record if they cancel.

If that is the case and you have set the context variable defaultRecord to what you want, and you have that as your Default property for the gallery, then consider using a Reset(Gallery1) in your Cancel.OnSelect formula.  That would be about the only change you would need to make (other than getting rid of the timers).

 

I hope this is clear and helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes 

HI Randy,
Thank you for your response,  yes that is what I want to happen but for some reason it doesn't work.  The behavior I'm seeing it that the Gallery goes into View mode before it has a chance to change back to the default item.

So for example i have my Gallery which is in View mode,  click on button to change the mode to Edit.  Select another item in the Gallery other than the default.  Decide to change my mind and click on the Cancel button which should reset the Gallery back to default and change the diaplymode to View.  But I'm actually getting is the Gallery goes into View mode before it has a chance to change selected item back to to the Default. So it stays on the selected Item.

If I don't change the DisplayMode back to View when i cancel it works fine. 

@stefen 

Did you try to add the suggested Reset(Gallery1) in your Cancel.OnSelect formula?  That should resolve that issue.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Hi Randy,

Yes,  for my Cancel.OnSelect i have tried 
Reset(Gallery3);
UpdateContext({editMode: false})

And 
UpdateContext({defaultRecord: {}}); UpdateContext({defaultRecord: LookUp(colGallery, ID = 2 )});
Reset(Gallery3);
UpdateContext({editMode: false})

If i remove the last line UpdateContext({editMode: false}) it works fine expect the Gallery is still in Edit Mode

@stefen 

Yeah, it's a little odd what you are trying to accomplish with the Gallery.  The Gallery DisplayMode needs to be in Edit mode to respond to any changes (as you've seen from your timer attempt).

Let's go another way...

I don't know what controls you have in your Gallery or how they respond to editMode - are they set to "respond" to editMode, or are they set to Parent.DisplayMode?

If they are Parent.DisplayMode, then change them to editMode.

Then, adjust your control formulas as follows:

 

Gallery1 -

    Default :  Lookup(colGallery, ID=2)

    DisplayMode : Edit

    Selectable : If(editMode, true, false)

 

Edit - 

   OnSelect : UpdateContext({editMode:true})

 

Cancel - 

   OnSelect : UpdateContext({editMode:false}) ; Reset(Gallery1)

 

See how that fairs out for you.

What we did was stop trying to make DisplayMode keep us from doing things in the Gallery and instead made the controls in the Template respond to if they are editable or not.  Then, for the Gallery, we just forced the Selectable ability on or off depending on edit mode.

 

I believe that will give you what you are looking for - although a slightly different way.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

Hi Randy,

Have just tried your solution and that work... thank you soo much.. 

Helpful resources

Announcements
News & Announcements

Community Blog

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

Power Apps Community Call

Power Apps Community Call- January

Check out the Power Apps Community Call for January 2021

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (11,713)