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.
1 ACCEPTED SOLUTION

Accepted Solutions

I did find a solution, but you will have to work it into your existing formula so everything works correctly for collecting and removing.

 

You can remove like this:

 

 

RemoveIf(CollectionX, !(CollectionField in ComboBoxX.SelectedItems.Value))

 

 In my case it's regions so it looks like this:

 

RemoveIf(Markets, !(Region in ComboBox1.SelectedItems.Value))

 



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.

View solution in original post

8 REPLIES 8
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.
MGeale
Helper I
Helper I

Did you by chance ever get a solution to this because I'm in the exact same dilemma!

What my thought process was/is to do was just remove the value from a new collection, then do a comparison with two collections (inclusive of the new one) and just have a squiz if those values don't exist in one.

Would be using flow to edit my schema.

Cheers!

I did not back then, but I might revisit it.    Since I only had two selections, I just switched and used checkboxes.    I may have a solution for you, though, let me think about it and I will get back to you.



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.

I did find a solution, but you will have to work it into your existing formula so everything works correctly for collecting and removing.

 

You can remove like this:

 

 

RemoveIf(CollectionX, !(CollectionField in ComboBoxX.SelectedItems.Value))

 

 In my case it's regions so it looks like this:

 

RemoveIf(Markets, !(Region in ComboBox1.SelectedItems.Value))

 



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.
MGeale
Helper I
Helper I

Awesome mate - thanks a bunch. Quite literally 5 minutes after posting this, I ended up finding a solution myself albeit a janky one. But hey...if it works, it works!

Thanks a bunch for responding 🙂

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (1,728)