Solved

How to copy data from one list to another programmatically in Flex

Posted on 2009-03-29
7
666 Views
Last Modified: 2012-05-06
My question is this.  

I have a datagrid which is bound to an XML collection.
I have a blank list.

I have drag enabled on the data grid and drop enabled on the list.

I am able to drag and drop between the lists (this is working fine).

What I am trying to replicate is the scenario where you have a button ( > ) between the lists which will copy the highlighted record to the list as if you had dragged and dropped it.

Hope this makes sense, let me know if you need anything clarifying.

Thanks in advance,
Oli
0
Comment
Question by:olifarago
  • 5
  • 2
7 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 24016813
When pressing the button, remove the selected item out of the XMLCollection and push in into the list bound to the List.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24016814
Could you maybe show us the code you already have?
0
 
LVL 9

Author Comment

by:olifarago
ID: 24016917
I'm really not sure whata you are suggesting.
Attached is a snippet which is a simple example of the scenario.

Oli

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="260">
 
    <mx:Model id="testfruit">
      <fruits>
        <fruit label="Apple"/>
        <fruit label="Banana"/>
        <fruit label="Cherry"/>
        <fruit label="Date"/>
        <fruit label="Pear"/>
      </fruits>
    </mx:Model>
    
    
	<mx:List x="10" y="10" width="160" height="238" dataProvider="{testfruit.fruit}" dragEnabled="true"></mx:List>
	<mx:List x="226" y="10" height="238" width="160" dropEnabled="true"></mx:List>
	<mx:Button x="178" y="119" label="&gt;"/>
	
</mx:Application>

Open in new window

0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 37

Expert Comment

by:zzynx
ID: 24017045
Consider this
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="260" creationComplete="onComplete()">
 
 	<mx:Script>
 		<![CDATA[
 			import mx.collections.ArrayCollection;
            [Bindable] private var testfruit:ArrayCollection = new ArrayCollection();
            [Bindable] private var testfruit2:ArrayCollection = new ArrayCollection();
 		
 			private function onClick():void {
 				var item:String = String(testfruit.removeItemAt(list1.selectedIndex));
 				testfruit2.addItem(item);
 			}
 			
 			private function onComplete():void {
 				testfruit.addItem("Apple");
 				testfruit.addItem("Banana");
 				testfruit.addItem("Cherry");
 				testfruit.addItem("Date");
 				testfruit.addItem("Pear");
 			}
 		]]>
 	</mx:Script>
 
        <mx:List id="list1" x="10" y="10" width="160" height="238" dataProvider="{testfruit}" dragEnabled="true"></mx:List>
        <mx:List id="list2" x="226" y="10" height="238" width="160" dataProvider="{testfruit2}"  dropEnabled="true"></mx:List>
        <mx:Button id="_btn" x="178" y="119" label="&gt;" click="onClick()"/>
        
</mx:Application>

Open in new window

0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 24017087
Oh, sorry. You don't want the item to be moved, but to be copied.
Then just replace this line

var item:String = String(testfruit.removeItemAt(list1.selectedIndex));

by

var item:String = String(testfruit.getItemAt(list1.selectedIndex));

Also, to avoid problems when nothing is selected you'd better write that method like this:

                   private function onClick():void {
                         if (list1.selectedIndex>-1) {
                              var item:String = String(testfruit.getItemAt(list1.selectedIndex));
                               testfruit2.addItem(item);
                         }
                   }
0
 
LVL 9

Author Comment

by:olifarago
ID: 24017292
zzynx, thanks for this.
As I was using some more detailed XML records I changed to using Object instead of String. Using our example woudl be:
                   private function onClick():void {
                         if (list1.selectedIndex>-1) {
                              var item:Object= testfruit.getItemAt(list1.selectedIndex);
                               testfruit2.addItem(item);
                         }
                   }
But this is exactly what I needed. Thanks for the guidance.
Oli
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24017745
>> But this is exactly what I needed. Thanks for the guidance.
You're welcome.
Thanx 4 axxepting
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adobe flex charting question 3 264
Getting rid of an unwanted URL 5 228
Need to have horizontal scrollbar in AdvancedDatagrid next to the freezed columns. 4 358
doubt future Flex 4 429
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
For months I had no idea how to 'discover' the IP address of the other end of a link (without asking someone who knows), and it drove me batty. Think about it. You can't use Cisco Discovery Protocol (CDP) because it's not implemented on the ASAs.…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question