Hi Thank you for taking your time to read this.
I am trying to add the check box values to a collection as below:
I have a screen with gallery with many checkboxes lets say Chk1,Chk2,Chk3 etc., whose text values are Checkbox1,Checkbox2,Checkbox3 so on., which have default values fetched from a SQL data source.
I have two collections named ColRemoveItem and ColAddItem. Now I want to add the text value of the checkboxes into collection ColRemoveItem if the user changes the checkbox value from default value(if it is true) and make it to false ,in the same way I want to add the text value of the checkbox into collection ColAddItem if the user changes the checkbox value from default value(if it is false) and make it to true.
And also I want to remove the item from the respective collection if the user makes the checkbox values back to default value.
I have tried assigning the default checkboxes values to some variables and checking the user input for checkboxes with variables but it has become hectic as there are many checkboxes and many variables are needed. Could you please help me to provide the best solution for this problem?
Solved! Go to Solution.
Hey @Shalom47 ,
Before adding item colAddItem and colRemoveItem, I changed the code to check the SQL datasource for default values.
Oncheck
If(CountRows(Filter(SQLdatasource,Key=ThisItem.Key && flag = true)) <=0,Collect(ColAddItem,ThisItem.Key));RemoveIf(ColRemoveItem,Value = ThisItem.Key)
OnUncheck
If(CountRows(Filter(SQLdatasource,Key=ThisItem.Key && flag = false)) <=0,Collect(ColRemoveItem,ThisItem.Key));RemoveIf(ColAddItem,Value = ThisItem.Key);
Where key is the checkbox value and flag hold the Boolean value.
Hey @Shalom47 ,
I assume the checkboxes are loaded in gallery from a SQL data source. I initialized two collections like below in Onscreen visible property to make sure to reset
ClearCollect(ColAddItem,Blank()); ClearCollect(ColRemoveItem,Blank());
Then use below code in Oncheck property of checkbox
Collect(ColAddItem,ThisItem.Value);
RemoveIf(ColRemoveItem,Value = ThisItem.Value);
Similarly, below code in OnUncheck property of checkbox
RemoveIf(ColAddItem,Value = ThisItem.Value);
Collect(ColRemoveItem,ThisItem.Value)
Finally, colAddItem will hold all checked values and colRemoveItem will hold all unchecked items after screen loads with its defualt checkboxes values.
Hi @Ashwin7104
Thanks for your reply,
I have tried the suggested method but it is also taking the default values into collection. For example: If checbox1 is checked by default and the user unchecks and checks it again(now the checkbox value is equal to the default value) still it is being loaded into collection. But I don't want the default values of checkboxes to be loaded into the collection. The checkbox values must be captured only when they are changed from their default values and removed from the respective collection if the user changes them back to their default values
Hey @Shalom47 ,
Before adding item colAddItem and colRemoveItem, I changed the code to check the SQL datasource for default values.
Oncheck
If(CountRows(Filter(SQLdatasource,Key=ThisItem.Key && flag = true)) <=0,Collect(ColAddItem,ThisItem.Key));RemoveIf(ColRemoveItem,Value = ThisItem.Key)
OnUncheck
If(CountRows(Filter(SQLdatasource,Key=ThisItem.Key && flag = false)) <=0,Collect(ColRemoveItem,ThisItem.Key));RemoveIf(ColAddItem,Value = ThisItem.Key);
Where key is the checkbox value and flag hold the Boolean value.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
182 | |
52 | |
41 | |
36 | |
29 |
User | Count |
---|---|
242 | |
82 | |
71 | |
69 | |
66 |