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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,092)