4 Replies Latest reply on Aug 11, 2009 10:14 PM by Venkat,Flex Developer

    Regarding datagrid replaceItemAt(...)

    Venkat,Flex Developer

      Flex 1.5 i am using the datagrid property replaceItemAt(...) for sending data from child mxml text input values to parent mxml grid. It is working. But i am migrating my flex applciation framework from 1.5 to 2. In Flex 2 it is not working with the same code even not saying any error. Please consider this criteria.

       

      I am having       item id| item name| price| Qty| VAT | discount| total            columns in parent data grid.

                                1          ABC          30    5     7          2        (XYZ)

      Through edit button i am getting these values in popup screen (child mxml file) in text boxes. After changing the VAT from 7 to 9 then by using the parent datagrid poperty replaceItemAt(...) i am setting up the datagridcolumn value from 7 to 9.

        • 1. Re: Regarding datagrid replaceItemAt(...)
          Gregory Lafrance Level 6

          You can try this:

           

          import mx.core.Application.application;

           

          private var app:Object = mx.core.Application.application;

           

          app.myDatagrid.dataProvider.replaceItemAt(...)

           

          The best way to communicate between popups and the main app is using custom events. See my flex cookbook post on using custom events. You often need to add event listeners to systemManager because popups are in their own display list after systemManager.

           

          http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postI d=11246

           

          If this post answers your question or helps, please mark it as such.

          • 2. Re: Regarding datagrid replaceItemAt(...)
            Venkat,Flex Developer Level 1

            Hello ,

             

                 thanks for your reply... But the datagrid property replaceItemAt(...) is not available in Flex2. But I am using this one in our application Flex 1.5. So while I tried the below code the same thing happens. If i am not given out my question correctly sorry. Once again i explain. The below codes are for Flex 1.5. But they are not working in Flex 2. Because in Flex 2  the property replaceItemAt is not available. I hope this is the reason. is there any mistakes on my interpretation? If it is then what is the solution? Can you please help me?

             

            The below datagrid is in our Parent mxml file:

            ------------------------------------------------------------------

             

            <mx:DataGrid id="dg" width="100%" height="100%"  rowCount="5">
                 <mx:columns>
                   <mx:Array>
                      <mx:DataGridColumn  dataField="itemcode" />
                      <mx:DataGridColumn  dataField="itemdescription"/>
                      <mx:DataGridColumn  textAlign="right" dataField="vatper"  />
                      <mx:DataGridColumn  textAlign="right" dataField="quantity"  />

             

                      <mx:DataGridColumn  textAlign="right" dataField="unitprce"  />
                      <mx:DataGridColumn textAlign="right" dataField="discountper"  />
                   </mx:Array>
                 </mx:columns>
               </mx:DataGrid>

             

            The below code is in our Child mxml file for setting up the edited values from child into parent datagridcolumns:

            ------------------------------------------------------------------------------------------ ----------------------------------------------------------------------

             

            parentApplication.dg.dataProvider.replaceItemAt(parentApplication.dg.selectedIndex,
                                {itemcode:itemcode.text, itemdescription:itemdescription.text,vatper:vatid.selectedItem.label,
                                quantity:MyNumberFormatter.rformat(quantity.text), unitprce:MyCurrencyFormatter.rformat(unitprce.text), discountper:MyCurrencyFormatter.rformat(discountper.text)});

            • 3. Re: Regarding datagrid replaceItemAt(...)
              Gregory Lafrance Level 6

              Make the data provider an ArrayCollection or XMLListCollection and use setItemAt().

               

               

              If this post answers your question or helps, please mark it as such.

              • 4. Re: Regarding datagrid replaceItemAt(...)
                Venkat,Flex Developer Level 1

                Hi thanks... it is working while i am tried ArrayCollection... I used the below code

                 

                ArrayCollection(parentApplication.dg.dataProvider).setItemAt(....)