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

Set checkbox value programatically

The question I'd like to ask here is actually very simple.  So I'll put the question first and just in case the full context is underneath it.  Thanks!

 

THE QUESTION:

I want to set a checkbox value from the OnSelect of a button.  I thought I could do it by entering the following to the OnSelect formula of the button:

 

cbx_AssignedToMe.Value = false

 

Entering this formula does not result in any error.  But, alas, life is not this simple and when I press the button nothing happens.

 

I've searched around and this question always seems to get answered by explaining about the default value.  But I don't think that applies to my scenario.  I want to clear the checkbox programatically.  How can I do it?


THE CONTEXT:
I have built a filter screen with a bunch of different data filters that can be set.  On this screen are two checkboxes which act as simple helpers to set up two of the filters to the current user.  In the grab below, you can see that because I set the "Assigned to me" checkbox, the associated Assigned to: textbox got disabled and the user was automatically assigned to me.

bh4017_1-1624898760510.png

 

 

At the bottom of the screen I have a clear filters button which has the job of resetting all the filters.  As part of this, I want to clear the checkboxes back to false.


The filters themselves are easy to clear as I have them set up as variables and I can just use the Set(variable, value) method to do it.  This does result in all my filters being cleared.  But unfortunatley the checkboxes (if checked) stay checked and I need to clear them programatically.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TheRobRush
Super User
Super User

This is an example that will show you how to do this, not coded for your exact situation.

In my example a single button sets both check and uncheck status, in yours you can split this between two buttons.

 

Code for onselect of the button is.

If(checkVar=true,
   Set(checkVar,false),
   Set(checkVar,true))

 

Then you set the Default code of your checkbox to

 

checkVar

 

as checkVar is cycled between true and false by onselects the checkbox will check and uncheck itself

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

View solution in original post

2 REPLIES 2
TheRobRush
Super User
Super User

This is an example that will show you how to do this, not coded for your exact situation.

In my example a single button sets both check and uncheck status, in yours you can split this between two buttons.

 

Code for onselect of the button is.

If(checkVar=true,
   Set(checkVar,false),
   Set(checkVar,true))

 

Then you set the Default code of your checkbox to

 

checkVar

 

as checkVar is cycled between true and false by onselects the checkbox will check and uncheck itself

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

View solution in original post

Thank you - I was able to adapt your solution to suit my scenario.  In my scenario I am only concerned with clearing the checkbox via a button, never checking them.  So the approach is different but the basis of your solution is sound and I've got it working.

 

It does seem like a total 'round the houses' way to do something that I feel should be very simple.  I think I should be able to assign the checkbox value directly.

 

But there you go, it is what it is and it's working - thanks again.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,165)