I have a checkbox inside a gallery with a formula set on the Visible property. Based on the Visible status of the checkbox I want to do some logic in the app.
Now, the formula in the property evaluates normally and it shows/hides my checkbox accordingly, but if I try to use checkbox.Visible in other formulas looks like it is always 'false', even when the checkbox is visible on the page.
In order to test this I have added a label on the page and I set it's Text property to checkbox.Visible. As you can see below, the checkbox is clearly visible on the page, but the value displayed in the label is 'false':
My problem with this is that I have to duplicate the formula from the Visible property, adding load on the app and duplicating code... hopefully this can be looked at and fixed in the next releases 🙂
I think this is because that your checkbox is placed in a data card in gallery control. Each card in this gallery will have a checkbox with different status and all of them are treated as checkbox in PowerApps. This is why your Label cannot show the right result with checkbox.Visible.
I am not using data cards... I am using a simple gallery with checkboxes in it. The label I was testing with was also part of the gallery. So I'm not sure I understand why is that correct, considering the checkbox is clearly visible on the page.
When you insert an control inside a Gallery, it will be inside a data cards.
I'm sorry, but this still doesn't make any logical sense to me...
Since the PowerApp is capable of evaluating correctly the Visible formula on the checkbox, why is not able to use that value outside of the checkbox?
You can't have something clearly visible on the page, and when you use that property in another control to return 'false'...
This seemingly strange behavior is because the Gallery is meant to display lists of items. The elements inside the gallery act as a template and are repeated for each item in the Gallery. To see what I mean, just insert a vertical Gallery.
Back to the case of the Checkbox. Let's say I insert a checkbox in the Gallery, name it ReviewCheckbox, and set Visible to a formula that evaluates to true for odd-numbered items and false for even-numbered items. Outside the checkbox, it's not really clear what ReviewCheckbox.Visible should be, because PowerApps does not know which instance of ReviewCheckbox to use. Is it the ReviewCheckbox of the first item or the second item, etc?
It would be a nice feature to prevent referencing Gallery elements from outside the Gallery. Or have a warning.
@tahoonis absolutely correct.
The correct way to reference controls in the gallery template should be either through the .Selected property, like this:
Or collectively like this for example:
Sum(Gallery1.AllItems, If(ReviewCheckBox.Visible, 1, 0))
However, this does not currently work, as only some of the properties of controls are available outside the gallery in this way.
Here is the work around:
Sum(Gallery1.AllItems,If(Label1.Text="true", 1, 0))
That is all you need, screenshot below, please let me know what you think.
Thanks for the explanation, it somehow makes more sense now.
The reason why I was confused is that the formula which hides/shows the checkbox validates the same for all the checkboxes in the gallery, so it's not the case when 1st is visible and 2nd is not... is all of them, or none of them.
I have ended up just duplicating the formula outside the gallery... not the best solution but it works.
However, @Meneghino nice solution 🙂 I haven't give it a try, but I believe it definitely works.
Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.
Fill out a quick form to claim your user group badge now!
Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities
Features releasing from October 2019 through March 2020
Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.
Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications