cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JR-BejeweledOne
Super User
Super User

Remove Items from collection when combobox selection is removed

I have an App where I am populating a collection with all matching items based on the selection in a combobox.    There are 2 options in the ComboBox and the user can choose one or both.    The collection is populated with the matching items for the selections made in the ComboBox.

 

Disclaimer:   I have this working beautifully!   I am NOT looking for solutions on how to accomplish the above.

 

What I need however are suggestions on how to trigger the removal of the same matching items if an item is deselected in the combobox.

 

I know how to do the removeif to remove all the matching items.  What I am having trouble figuring out is how to determine that one of the selections has been removed from the combobox so I can then remove the items from the collection.

 

I have looked at a few different options, but because of the way the combobox works, all seem to be problematic.

 

Here an example of what I need to do:

 

ComboBox Items = European Union and North America

When one is selected, all the matching items are added to the collection.  If the other one is then selected then all those matching items are added to the collection.   So the collection can contain items that match one or both choices.

 

If I remove European Union from the ComboBox I need to remove all the matching European Union items from the collection and if I remove North America from the ComboBox I need to remove all the matching North America items from the collection.

 

I suspect it's going to have to be some complicated solution with comparing values in variables or something like that.

 

All suggestions are welcome.   I miss the InfoPath mult-select checkbox control.   😞



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
4 REPLIES 4
Jeff_Thorpe
Super User
Super User

I am not sure how the collection is being used, so this might not be a work in your case. You use the OnChange property of the Combo box to do a ClearCollect() and basically reset the collection based on the items selected in the Combo box.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

You would think that it would be that easy but it's not.    Full scenario, this is a mock 'repeating table' scenario.

 

Here is the behavior I have found regardless of which one I select first. 

 

When I select European Union all 28 associated countries are added to the collection, then when I select North America, 2 additional countries are added.   So now I have 36 entries in my collection.

 

Because of the way the selected item value works in the combobox, if I remove North America, then the value is European Union again and those 34 countries are added a second time to my collection giving me 70 items in my collection and vice versa.

 

 

 

 

 



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

@JR-BejeweledOne ,

@Jeff_Thorpe 's solution is correct - I suspect you are using Collect instead of ClearCollect.

If I use ClearCollect, then each time a new selection is made from my combobox, it erases the previously selected items.

 

The point of the combobox in my app is to be able to select multiple items and each time add to the collection, not change it.

 



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

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

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.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (843)