cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ilied
Level: Powered On

Move items from one Listbox to another

Hi!

 

I have supposedly a very simple problem, but I can't find a working solution for this. The problem is as follows:

 

I have two Listboxes. Other one has the data, the other one is empty. There is a button that sends all the selected items to the other Listbox. However, when the item is sent to the other Listbox, it is just copied, not moved. I want the item gone from the other Listbox. To make matters more interesting, the datasource is a string of text, which has been split into different values for the Listbox. Is there a workaround for this?

 

Attached pictures of the problem. The current code is also visible.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Move items from one Listbox to another

@ilied 

I've made a demo app to show you my method.

 

test.png

 

Put this code in the OnVisible property of your screen

Set(myTextString,"Test 1/Test 2/Test 3/Test 4");
ClearCollect(myItems,RenameColumns(Split(myTextString,"/"),"Result","Value"));
ClearCollect(myItems2,["ABC"]);
Clear(myItems2);

 

Use this code in the Items property of ListBox1

myItems

 

Use this code in the Items property of ListBox2

myItems2

 

Place this code in the OnSelect property of your "Move Selected" button

ClearCollect(mySelection,ListBox1.SelectedItems);
ForAll(mySelection,Patch(myItems2,Defaults(myItems2),{Value:mySelection[@Value]}));
RemoveIf(myItems,Value in ListBox1.SelectedItems)

 

Let me know if you have any questions

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Move items from one Listbox to another

@ilied 

I've made a demo app to show you my method.

 

test.png

 

Put this code in the OnVisible property of your screen

Set(myTextString,"Test 1/Test 2/Test 3/Test 4");
ClearCollect(myItems,RenameColumns(Split(myTextString,"/"),"Result","Value"));
ClearCollect(myItems2,["ABC"]);
Clear(myItems2);

 

Use this code in the Items property of ListBox1

myItems

 

Use this code in the Items property of ListBox2

myItems2

 

Place this code in the OnSelect property of your "Move Selected" button

ClearCollect(mySelection,ListBox1.SelectedItems);
ForAll(mySelection,Patch(myItems2,Defaults(myItems2),{Value:mySelection[@Value]}));
RemoveIf(myItems,Value in ListBox1.SelectedItems)

 

Let me know if you have any questions

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

View solution in original post

ilied
Level: Powered On

Re: Move items from one Listbox to another

Thank you for the reply. Works like a charm. 🙂

 

 

ilied
Level: Powered On

Re: Move items from one Listbox to another

This works, but I ran into a different problem. I changed the source data to a database and i'm using a form to update the items in the listbox back to the database. The problem is, I can only choose "Listbox.SelectedItems" as the data to update. Is it possible to send everything in the list to the database, regardless if it's selected or not?

Super User
Super User

Re: Move items from one Listbox to another

@ilied 

Yes.  ListBox.SelectedItems would target the selected items wheras ListBox.AllItems would target the entire contents whether selected or not.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

ilied
Level: Powered On

Re: Move items from one Listbox to another

Allitems is not an option, but I solved the problem by using Combobox. Thanks for the help!

Super User
Super User

Re: Move items from one Listbox to another

@ilied 

I'm glad to hear your problem is now resolved 🙂

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,517)