web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Removing an item from ...
Power Apps
Unanswered

Removing an item from a collection?

(0) ShareShare
ReportReport
Posted on by 377

Hi

I have a List Box and OnSelect I want to add or remove to/from a Collection.

The logic is that if the list box item is selected then its added to the collection.

If the list box item is deselected then its removed from the collection.

 

I try this and it adds to the collection but doesn't remove from the collection.

 

Any ideas why?

 

Thanks

P

 

 

Notify("Am I blank? Selected is " & listboxClose.Selected.Key);
If(IsBlank(listboxClose.Selected.Key),
RemoveIf(myCloseFirms, galCloseFirms.Selected.FirmName = ChosenFirmName & CloseFirmName = listboxClose.Selected.Key),
Collect(
        myCloseFirms,
        {
                ChosenFirmID:galCloseFirms.Selected.FirmID,
                ChosenFirmName:galCloseFirms.Selected.FirmName,
                CloseFirmName:listboxClose.Selected.Key
         }
)
);


Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    hey @pmwhelan 

     

    you can try this approach:

    // Assume 'selectedItems' is a collection that tracks the selected state
    // This snippet goes in the OnSelect property of your ListBox
    
    // Check if the currently selected item is in the 'selectedItems' collection
    If(
     LookUp(selectedItems, CloseFirmName = listboxClose.Selected.Key),
     // If it is, remove it
     Remove(selectedItems, LookUp(selectedItems, CloseFirmName = listboxClose.Selected.Key)),
     // If it's not, add it
     Collect(selectedItems, {CloseFirmName: listboxClose.Selected.Key})
    );
    
    // Then, sync 'myCloseFirms' with 'selectedItems'
    Clear(myCloseFirms); 
    ForAll(
     selectedItems as selectedItem,
     Collect(
     myCloseFirms,
     {
     ChosenFirmID: galCloseFirms.Selected.FirmID, // You might need to adjust this logic
     ChosenFirmName: galCloseFirms.Selected.FirmName,
     CloseFirmName: selectedItem.CloseFirmName
     }
     )
    );
    

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • pmwhelan Profile Picture
    377 on at

    Thanks but I'm getting errors with that

     

    pmwhelan_0-1709231881145.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard