2 Replies Latest reply on Sep 25, 2009 10:45 AM by lee704

    Bind two DataGrids so that a change in one will be refelected in another

    lee704

      Is there a simple way to bind two DataGrids so that a change in one will be refelected in another?  I have two DataGrids.  One will be editable and the other will be used to display the information from the editable DataGrid in a confirmation section.  Is there a simple example  out there for doing this?

       

      Thanks,

      Lee

        • 1. Re: Bind two DataGrids so that a change in one will be refelected in another
          Flex harUI Adobe Employee

          Yes, but it depends on how your data is organized.  If you have a central ArrayCollection, both DG's should use that as the dataProvider.  If you don't you can try to find a way to assign the dataProvider.list to the dataProvider of the other DG.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Bind two DataGrids so that a change in one will be refelected in another
            lee704 Level 1

            I may have figured it out.  It seems to be working with:

             

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

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

            layout="absolute"

            creationComplete="initComponent()"

            xmlns:views="com.views.*"

            width="100%"

            height="100%">

             

            <mx:Script>

            <![CDATA[

            import mx.collections.ArrayCollection;

            import mx.rpc.events.ResultEvent;

             

            private var currentIndex:int=0;

             

             

            private function initComponent():void

            {

            refreshList(null);

            }

             

            public function refreshList(event:Event):void

            {

            this.roArtist.getArtists();

            }

             

            private function getArtists_result(event:ResultEvent):void

            {

            dgArtistList.dataProvider=event.result as ArrayCollection;

            dgArtistList.selectedIndex=currentIndex;

            dgArtistListConfirm.dataProvider=event.result as ArrayCollection;

            dgArtistListConfirm.selectedIndex=currentIndex;

            }

             

             

            ]]>

            </mx:Script>

             

            <mx:RemoteObject id="roArtist"

            showBusyCursor="true"

            destination="ColdFusion"

            source="art.src.cfc.artist">

            <mx:method name="getArtists"

               result="getArtists_result(event)">

            </mx:method>

            </mx:RemoteObject>

             

             

             

            <mx:Label x="10"

              y="10"

              text="Entry"

              fontWeight="bold"/>

             

            <mx:DataGrid id="dgArtistList"

            x="10"

            y="36"

            editable="true">

            <mx:columns>

            <mx:DataGridColumn dataField="ARTISTID"

               headerText="ArtistID"

               editable="false"/>

            <mx:DataGridColumn dataField="FIRSTNAME"

               headerText="First Name"

               editable="true"/>

            <mx:DataGridColumn dataField="LASTNAME"

               headerText="Last Name"

               editable="true"/>

            </mx:columns>

            </mx:DataGrid>

             

            <mx:Label x="10"

              y="210"

              text="Confirmation"

              fontWeight="bold"/>

             

            <mx:DataGrid id="dgArtistListConfirm"

            x="10"

            y="236" dataProvider="{ArrayCollection}">

            <mx:columns>

            <mx:DataGridColumn dataField="ARTISTID"

               headerText="ArtistID"/>

            <mx:DataGridColumn dataField="FIRSTNAME"

               headerText="First Name"/>

            <mx:DataGridColumn dataField="LASTNAME"

               headerText="Last Name"/>

            </mx:columns>

            </mx:DataGrid>

             

            </mx:Application>

             

            I need to do some testing.

             

            Thanks!