Here is a sample app that does what I think you want.

Tracy

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" horizontalAlign="left"

                        initialize="initApp()">

<mx:Script><![CDATA[

            public var gsBindMe:String = "Change me!" ;                                                        //

            private var aDP2:Array;

            private function initApp():Void

            {

                        aDP2 = new Array();

                        aDP2.push(["Pink Floyd",29.99,"Meddle"])

                        aDP2.push(["Pink Floyd",29.99,"More"])

                        aDP2.push(["Genesis",22.99,"Trespass"])

                        aDP2.push(["Yes",22.99,"Close to the Edge"])

            }//        

            import mx.containers.TitleWindow;

            import mx.managers.PopUpManager;

            private function showTitleWindow():Void

            {

                        var aSelected:Array = dg2.selectedItems;

                        var oInitObj:Object = new Object();

                        oInitObj.title = "Title Window Data";         //built-in property

                        oInitObj.width = 600;                                                                  //built-in property

                        oInitObj.height = 600;                                                                 //built-in property

                        oInitObj.mainApp = this;                                                 //user-added property. reference to main app

                        oInitObj.gsMyString = tiMyString.text;     //user-added property. will contain value of text input

                        oInitObj.itemsSelected = aSelected;                    //user-added property. will contain array

                        var titleWindowInstance:Object =

                                                TitleWindow(PopUpManager.createPopUp(this,

                                                                                                                                                                                                            TitleWindowData,

                                                                                                                                                                                                            false,

                                                                                                                                                                                                            oInitObj,

                                                                                                                                                                                                            false));                                                  //instantiate and show the title window

                       

                        titleWindowInstance.centerPopUp(this)

                        titleWindowInstance.gnMyNumber = parseFloat(tiMyNumber.text);             //titleWindowInstance must be Object to use this

            }

]]></mx:Script>

 

            <mx:DataGrid id="dg2" multipleSelection="true"

                                    dataProvider="{aDP2}" >

                        <mx:columns>

                                    <mx:Array>

                                                <mx:DataGridColumn headerText="Artist" columnName="0" />

                                                <mx:DataGridColumn headerText="Price" columnName="1" editable="true"/>

                                                <mx:DataGridColumn headerText="Album" columnName="2" />

                                    </mx:Array>

                        </mx:columns>                        

            </mx:DataGrid>

            <mx:HBox >

                        <mx:Label text="MyString:" width="100" />

                        <mx:TextInput id="tiMyString" text="my string" />

            </mx:HBox>

            <mx:HBox >

                        <mx:Label text="MyNumber:"  width="100"/>

                        <mx:TextInput id="tiMyNumber"  text="99"/>

            </mx:HBox>

            <mx:HBox >

                        <mx:Label text="Bind Me"  width="100"/>

                        <mx:TextInput id="tiBindMe" text="{gsBindMe}"

                                    change="gsBindMe = tiBindMe.text"/>

            </mx:HBox>     

            <mx:Button label="ShowTitleWindow{newline}Non-Modal" click="showTitleWindow()"/>

</mx:Application>

 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of rgwilson26
Sent: Tuesday, May 16, 2006 3:58 PM
To: [email protected]
Subject: [flexcoders] Re: Passing data between two datagrids

 

I got it to work with the hard coded data.  However, I cannot seem to pass an array in my initObj correctly.  Do I need another loop for my array or is there somthing else I am not seeing?

Thanks,

*******************
Main component
*****************

public var selectedTeamMembers:Array;
 
public function addMember(){
   var teamMemberObj = new Object();
   var selectedIndices:Array = new Array(dgTeamMemberName.length);
  
//loop through and pull all names in the datagrid
 for(var i=0; i < dgTeamMemberName.length; i++) {
 selectedIndices[i] = i;
 }
 dgTeamMemberName.selectedIndices = selectedIndices;
 for(var j=0; j < dgTeamMemberName.selectedIndices.length; j++){
      selectedTeamMembers = dgTeamMemberName.selectedItems[j].name;   //this array does not pass anything
}
// Create a new pop-up with and add all team members to pop-up datagrid
 
 var popup:Object  = mx.managers.PopUpManager.createPopUp(_root, comp.popUpBox, true, {teamMemberObj: selectedTeamMembers});
popup.addEventListener('teamMemberObject', this);
}


--- In [email protected], "Doug Lowder" <[EMAIL PROTECTED]> wrote:
>
> Hi Ryan,
>
> Define a variable in your popup component that you bind to the
> grid's dataprovider:
>
> var teamMemberData: Array;
> ...
> <mx:DataGrid id="dgTeamMemberAssignment2" width="100%"
> dataProvider="{teamMemberData}">
>
> Then, in your main component, pass the data for your popup's grid as
> the initObj. You can use this as a test:
>
> mx.managers.PopUpManager.createPopUp(_root, comp.popUpBox, true,
> { teamMemberData: [ {name: "A"}, {name: "B"}, {name: "C"} ] });
>
> From there, once you get that working, just create a new array
> containing the selected items from your main component's grid and
> pass that array rather than the dummy data. The initObj should look
> something like:
>
> { teamMemberData: mySelectedItemsArray }
>
>
> Hope that helps,
> Doug
>
> --- In [email protected], "rgwilson26" ryan.wilson@
> wrote:
> >
> > I am working on an app (Flex 1.5) that passes data from the main
> > apps dataGrid and sends it to a popUp with another dataGrid. I
> have
> > some logic that will select all the data in the main apps datagrid
> > and send it to the popUp, but it only sends the last value in my
> > main apps dataGrid..
> >
> > Does anyone have any suggestions of how to send all the values of
> my
> > main apps data grid to the popUps datagrid? I want the user to be
> > able to open the pop up with all the main app datagrid values so
> > they can add or delete them within the pop-up.
> >
> > Below is some sample code.
> >
> > Thanks,
> >
> >
> > **************************
> > Main component
> > ***************************
> > <mx:Script>
> > <![CDATA[
> >
> > public var selectedTeamMembers:String;
> >
> > public function addMember(){
> > var teamMemberObj = new Object();
> > var selectedIndices:Array = new Array
> > (dgTeamMemberName.length);
> >
> > //loop through and pull all names in the datagrid
> > for(var i=0; i < dgTeamMemberName.length; i++) {
> > selectedIndices[i] = i;
> > }
> > dgTeamMemberName.selectedIndices = selectedIndices;
> > for(var j=0; j <
> > dgTeamMemberName.selectedIndices.length; j++){
> > teamMemberObj.selectedTeamMembers =
> > dgTeamMemberName.selectedItems[j].name;
> > }
> > // Create a new pop-up with and add all team members
> > to pop-up datagrid
> > var popup:Object =
> > mx.managers.PopUpManager.createPopUp(_root, comp.popUpBox, true,
> > teamMemberObj);
> > popup.addEventListener('teamMemberObject', this);
> > }
> >
> >
> > ]]>
> > </mx:Script>
> >
> >
> >
> > <mx:DataGrid id="dgTeamMemberName">
> > <mx:columns>
> > <mx:Array>
> > <mx:DataGridColumn headerText="Name" columnName="name"/>
> > </mx:Array>
> > </mx:columns>
> > </mx:DataGrid>
> >
> > <mx:Button label="Add Team Member" click="addMember()"/>
> >
> > **************************
> > popUp component
> > ***************************
> > <mx:Script>
> > <![CDATA[
> >
> > private function initPopUp(){
> > if(selectedTeamMembers != ""){
> > dgTeamMemberAssignment2.addItem({name:
> > selectedTeamMembers});
> > }
> > }
> >
> >
> > ]]>
> > </mx:Script>
> >
> >
> > <mx:DataGrid id="dgTeamMemberAssignment2" width="100%">
> > <mx:columns>
> > <mx:Array>
> > <mx:DataGridColumn headerText="Team Member(s)
> > assignment" columnName="name" />
> > </mx:Array>
> > </mx:columns>
> > </mx:DataGrid>
> >
>




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to