2 Replies Latest reply on Jan 30, 2010 3:11 PM by 7546445

    How to add Column to DataGrid?

    7546445 Level 1

      I have simple mxml code

       

      <mx:DataGrid id="DGG"
                  
      editable="true">
         
      <mx:dataProvider>
             
      <fx:Object scheduledDate="4/1/2006"/>
         
      </mx:dataProvider>
      </mx:DataGrid>
      <s:Button id="SetBut"
                
      label="Set Array as Data Provider"
                
      click="SetDP(); AddBut.visible = true;"
                
      x="100.5"
                
      y="164"
                
      width="211"/>
      <s:Button id="AddBut"
                
      label="Add a column!"
                
      click="AddCol();"
                
      x="100.5"
                
      y="194"
                
      width="211"
                
      visible="false"/>
      <fx:Script>
          <![CDATA[
          import mx.controls.dataGridClasses.DataGridColumn;
          import mx.collections.ArrayCollection;

          [Bindable]
          public var MyAC:ArrayCollection=new ArrayCollection([{scheduledDate: "4/1/2006", homeTeam: "Chester Bucks"}]);

          public function SetDP():void
          {
          DGG.dataProvider=MyAC
          }

          public function AddCol():void
          {
          MyAC.addItem({scheduledDate: "4/5/2007", homeTeam: "Long Valley Hitters", Umpire: "Amanda Hugenkis"});
          DGG.columns.push(new DataGridColumn("Umpire"));
          }
          ]]>
      </fx:Script>

       

      I want to add rows to my table datagrid.

      (You can put this code in Flash or AIR app - it will compile with no errors, but will not add any columns=( )

      So could you please tell me - how to add a row dynamically to dataGrid?