1 Reply Latest reply on Jul 30, 2007 5:53 AM by Suren_kancherla

    Add colum to DataGrid with AS

    Celtar
      Hi !

      I am trying to add a colum to a datagrid using ActionScript.
      So far I manager to add the datagrid to my form element using :

      import mx.controls.DataGrid;
      import mx.controls.dataGridClasses.DataGridColumn;

      ...

      var myDataGrid:DataGrid=new DataGrid();
      myDataGrid.width=400;
      myDataGrid.id="MyDataGridx";
      listx.addChild(myDataGrid);

      Now I am trying to add three column to the dataGrid using :
      var location_dgc:DataGridColumn = new DataGridColumn("Location");
      location_dgc.width = 100;
      MyDataGridx.addColumn(location_dgc);

      I always get the same error : the method addColumn is undefined via the static reference import mx.controls.DataGrid

      Any suggestions ?

      Thanks.
        • 1. Re: Add colum to DataGrid with AS
          Suren_kancherla
          Hi !
          You can try in this way,

          var myDataGrid= new DataGrid;
          myDataGrid.width = 400;
          myDataGrid.id="MyDataGridx"

          var dgColumnsArr:Array =new Array;
          // columnsAC is a ArrayCollection will have the name of the as columnName and headerText as displayName
          ex : var columnsAC:ArrayCollection = new ArrayCollection([{columnName:"location",displayName:"Location"}]);
          for(var i:int=0;i<columnsAC.length;i++)
          {
          var columns:DataGridColumn = new DataGridColumn;
          columns.dataField = columnsAC .columnName;
          columns.headerText =columnsAC
          .displayName;
          dgColumnsArr =columns;
          }
          myDataGrid.dataProvider = dgAC; //ur data ArrayCollection
          myDataGrid.columns=dgColumnsArr; //assign array of columns to the DataGrid columns
          listx.addChild(myDataGrid);

          Thanks,