cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Advocate I
Advocate I

Condition color change form checkbox

Hi, again.

 

I have a frontpage with a circle in to represent task status. On an other screen I've got a gallery with tasks and checkboxes. My goal is to make this one single circle turn green when all the boxes are checked, and red as long as not every single one is checked. 

 

I used an If statement and so on, but the circle turns green as long as just one is checked.

 

Any advice?

1 ACCEPTED SOLUTION

Accepted Solutions

I suggest you follow these steps:

1. Insert a Label Example Label1 into the Gallery say Gallery1 {The Label will appear in each row of the Gallery as your checkbox) --- You can hide the Label

 

2. In the Text Property of Label1, put : 

   If(Checkbox2.Value,1,0)

 

3. On the OnSelect of the Button that navigate to the Frontpage put:

  Set(varDiff,CountRows(Gallery1.AllItems)-Sum(Gallery1.AllItems,Value(Label1.Text)))

 

or

 Set(varDiff,CountRows(Gallery1.AllItems)-Sum(Gallery1.AllItems,Value(Label1.Text)));Navigate(FrontPageScreen)

 

4. Finally in the fill property of the Circle icone on the frontpage:

   If(varDiff<>0,Red,Green)

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

View solution in original post

13 REPLIES 13
Super User II
Super User II

@AndyNorw 

Post your If statement and we can try to fix it for you.

I totally forgot my code, sorry.

 

For the circle object I used this:

 

If(CheckBox_Annet.Value=true; green; red)

 

I've got Norwegian as language, therefore the semicolons and not commas.

 

On the checkbox "OnCheck" to true and OnUncheck to false.

@AndyNorw 

If you have more than 1 checkbox that needs to be considered then the If statement needs to be.

 

If(CheckBox_Annet&&Checkbox2&&Checkbox3; Green; Red)

 

The If statement resolves  to either true or false.  There is no need for the .Value as it is implicit.  All of the checkboxes need to be true for the entire statement to be true.  There is also no need for the OnCheck or OnUncheck properties to be changed either.

Hi.

 

I suspected as much. Thank you so much. But what if the number of checkboxes exceed the number I've acounted for in the code? Is there some kind of Len() function to deal with this? Or do I have to set a maximum number of possible tasks and hardcode that number?

Super User II
Super User II

@AndyNorw 

I believe you are overthinking the problem.  Checkbox controls are either true or false.  In any formulas that you use, you can just use the name of the checkbox control and it will resolve to either true or false depending on whether it is checked or not.  

I'm very prone to overthinking I'm afraid.

 

The app is just a tasklist where people can add and check out tasks. The issue is that I dont want the Frontpage circle to change to green before all the tasks in the gallery are checked. In the pic, if I just check one box, then the circle turns green.

 

Checkbox.jpg

 

Super User II
Super User II

Hi @AndyNorw 

If you use the formula that I gave you in the Color property of the circle with all of the checkbox names chained with &&, then the color won't turn green until all of the checkboxes are checked. 

Hi again @Drrickryp , and sorry for being slow.

 

I tried the code, but I get an error; "Name invalid. This identifyer is not recognized"

 

The other checkboxes doesn't have a individual name, just the first one. The checkboxes after the first one gets autogenerated when i create a new task. I just set the first one on the top of the gallery.

Super User II
Super User II

I didn't quite get that you have the checkbox in a gallery.  I will have to rethink this.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (103,342)