PDA

View Full Version : pass data from datagrid1 to datagrid2


stonyx
08-16-2006, 08:25 PM
hi, i was wondering if anyone have an example of how to pass data from one datagrid to another like when drag & drop but just clicking on it

flexy
08-17-2006, 08:45 AM
This should help:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="serv.send()">
<mx:Script>
<![CDATA[
private function dgClick(item:Object):void{
dg2.dataProvider = item;
}
]]>
</mx:Script>
<mx:HTTPService id="serv" url="http://www.yoursite.co.uk/something.xml" useProxy="false"/>
<mx:Panel width="50%" height="100%" roundedBottomCorners="true" cornerRadius="25">
<mx:DataGrid id="dg1" dataProvider="{serv.lastResult.nodeName}" width="100%" click="dgClick(dg1.selectedItem)"/>
<mx:DataGrid id="dg2" width="100%"/>
</mx:Panel>
</mx:Application>

Tink
08-17-2006, 12:05 PM
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="serv.send()"> <mx:Script>
<![CDATA[
import flash.events.MouseEvent;

private function dgClick( event:MouseEvent ):void
{
dg2.dataProvider = DataGrid( event.currentTarget ).selectedItem;
}
]]>
</mx:Script>
<mx:HTTPService id="serv" url="http://www.yoursite.co.uk/something.xml" useProxy="false"/>
<mx:Panel width="50%" height="100%" roundedBottomCorners="true" cornerRadius="25">
<mx:DataGrid id="dg1" dataProvider="{serv.lastResult.nodeName}" width="100%" click="dgClick(event);"/>
<mx:DataGrid id="dg2" width="100%"/>
</mx:Panel>
</mx:Application>Not much difference there, but thats the way i would go about it.

u could also use<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="serv.send()">
<mx:HTTPService id="serv" url="http://www.yoursite.co.uk/something.xml" useProxy="false"/>
<mx:Panel width="50%" height="100%" roundedBottomCorners="true" cornerRadius="25">
<mx:DataGrid id="dg1" dataProvider="{serv.lastResult.nodeName}" width="100%" click="dg2.dataProvider = dg1.selectedItem"/>
<mx:DataGrid id="dg2" width="100%"/>
</mx:Panel>
</mx:Application>

stonyx
08-18-2006, 03:30 AM
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="serv.send()"> <mx:Script>
<![CDATA[
import flash.events.MouseEvent;

private function dgClick( event:MouseEvent ):void
{
dg2.dataProvider = DataGrid( event.currentTarget ).selectedItem;
}
]]>
</mx:Script>
<mx:HTTPService id="serv" url="http://www.yoursite.co.uk/something.xml" useProxy="false"/>
<mx:Panel width="50%" height="100%" roundedBottomCorners="true" cornerRadius="25">
<mx:DataGrid id="dg1" dataProvider="{serv.lastResult.nodeName}" width="100%" click="dgClick(event);"/>
<mx:DataGrid id="dg2" width="100%"/>
</mx:Panel>
</mx:Application>Not much difference there, but thats the way i would go about it.

u could also use<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="serv.send()">
<mx:HTTPService id="serv" url="http://www.yoursite.co.uk/something.xml" useProxy="false"/>
<mx:Panel width="50%" height="100%" roundedBottomCorners="true" cornerRadius="25">
<mx:DataGrid id="dg1" dataProvider="{serv.lastResult.nodeName}" width="100%" click="dg2.dataProvider = dg1.selectedItem"/>
<mx:DataGrid id="dg2" width="100%"/>
</mx:Panel>
</mx:Application>


tahnks for your fast reply
it work fine but when i select another item in the datagrid1
the item in datagrid2 won't stay
what i want is for datagrid2 to keep the last 5 items clicked in datagrid1

thanks

flexy
08-21-2006, 11:29 AM
Use instantiate your dg2 dataprovider as an ArrayCollection, then call the addItem method when a user selects an item from dg1.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="serv.send()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] private var dp:ArrayCollection = new ArrayCollection();
private function dgClick(item:Object):void{
dp.addItem(item);
}
]]>
</mx:Script>
<mx:HTTPService id="serv" url="http://your.xml" useProxy="false"/>
<mx:Panel width="50%" height="100%" roundedBottomCorners="true" cornerRadius="25">
<mx:DataGrid id="dg1" dataProvider="{serv.lastResult.nodeName}" width="100%" click="dgClick(dg1.selectedItem)"/>
<mx:DataGrid id="dg2" dataProvider="{dp}" width="100%"/>
</mx:Panel>
</mx:Application>

stonyx
08-23-2006, 12:30 AM
thanks for your help guys i just solve my problem

know what i'm looking for is to set focus on the new row i'm adding do you have any example