1 Reply Latest reply on Apr 8, 2009 6:44 AM by Michael Borbor

    problem in changing dataprovider

    san00001

      Hi,

       

      I have a Datagrid which contains List as Itemrenderer.I am providing data to the list through arraycollection.I need to change the dataprovider while clicking the button.I have two arraycollections a2 and a3.

       

                          var ac2:ArrayCollection = new ArrayCollection([ { TaskName: "A" }, { TaskName: "B" }, { TaskName: "C" } ]);
                          var ac3:ArrayCollection = new ArrayCollection([{TaskName: "D"},{TaskName: "E"},{TaskName: "F"}]); 

       

      At first the datagrid displays A B C.When i clicked the change button to change the dataprovider its displaying D A B insted of D E F

       

      The complete code is given below.Any one pls help me to solve tis problem.

       

      <?xml version="1.0"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
          <mx:Canvas id="can3" width="366"    height="286" label="Project Management Related Tasks">
                  <mx:Script>
                               <![CDATA[
                              import mx.collections.ArrayCollection;
                              import mx.events.CollectionEvent;
                              import mx.controls.Alert;
                             
                             
                              function changeDataprovider()
                              {
                                  dg.dataProvider=ac3;
                              }
                             
                             
                              function dataProvider():void
                               {
                                  dg.dataProvider=ac2;
                                     
                               }
                                  
                              
                          var ac2:ArrayCollection = new ArrayCollection([ { TaskName: "A" }, { TaskName: "B" }, { TaskName: "C" } ]);
                          var ac3:ArrayCollection = new ArrayCollection([{TaskName: "D"},{TaskName: "E"},{TaskName: "F"}]);   
                                 
             
                          ]]>         
                           </mx:Script>
                  <mx:DataGrid sortableColumns="true" id="dg" creationComplete="{ dataProvider();}"   alpha="2" resizableColumns="false"   width="100%" borderThickness="0" color="black" height="266" >
                      <mx:columns>
                          <mx:DataGridColumn color="navy"  headerText="Task Name" dataField="TaskName" fontWeight="normal">
                           <mx:itemRenderer>
                   <mx:Component>
                       <mx:HBox>
                       <mx:List  id="ManagementList" dragEnabled="true" creationComplete="data1()"   themeColor="white"  allowMultipleSelection="false"   width="85"         height="20" rowHeight="20" borderThickness="0" />
                             <mx:Script>
                               <![CDATA[
                              
                          
                     
                              function data1():void
                              {
                                  ManagementList.dataProvider = data.TaskName;
                              }
                             
                         
                               ]]>         
                           </mx:Script>
                         
                         </mx:HBox>
                        </mx:Component>
                   </mx:itemRenderer>
                  
                   </mx:DataGridColumn>
                   </mx:columns>
                       </mx:DataGrid>
                     
                      </mx:Canvas>
                      <mx:Button id="but" label="change" click="changeDataprovider()" />
      </mx:Application>

        • 1. Re: problem in changing dataprovider
          Michael Borbor Level 4

          If you remove this code snippet your app will work fine.

           <mx:itemRenderer>
                       <mx:Component>
                           <mx:HBox>
                          
          <mx:List  id="ManagementList" dragEnabled="true"
          creationComplete="data1()"   themeColor="white" 
          allowMultipleSelection="false"   width="85"         height="20"
          rowHeight="20" borderThickness="0" />
                                 <mx:Script>
                                   <![CDATA[
                                   
                               
                          
                                  function data1():void
                                  {
                                      ManagementList.dataProvider = data.TaskName;
                                  }
                                  
                              
                                   ]]>          
                               </mx:Script>
                              
                             </mx:HBox>
                            </mx:Component>
                       </mx:itemRenderer>
          

          I see you want to add an itemRenderer but I don't get why you need an script there, or what you need to accomplish.