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
Solved! Go to Solution.
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.
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.
@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.
Did you try to add the suggested Reset(Gallery1) in your Cancel.OnSelect formula? That should resolve that issue.
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
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.
Hi Randy,
Have just tried your solution and that work... thank you soo much..
Check out new user group experience and if you are a leader please create your group
Did you miss the call?? Check out the Power Apps Community Call here!
See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.
User | Count |
---|---|
272 | |
257 | |
87 | |
39 | |
34 |
User | Count |
---|---|
348 | |
249 | |
130 | |
68 | |
48 |