1 Reply Latest reply on Apr 5, 2007 12:12 PM by peterent

    DYnamic data grid through ActionScript

    mFlexDev Level 1
      Hi...
      I want to create a Data grid dynamically during runtime based on some input through action script.
      It will be helpful if some one can post me an example of how to creat the data grid dynamically and use all its common properties.

      Regards
        • 1. Re: DYnamic data grid through ActionScript
          peterent Level 2
          Please read the Flex 2 on the DataGrid class for the details, but here's the gist:

          var grid:DataGrid = new DataGrid();
          grid.dataProvider = someCollection; // same as dataProvider="{someCollection}" in MXML
          // set other properties here
          grid.setStyle( "alternateItemColors", [0xff0000,0x00ff00]); // same as alternateItemColors="[0xff0000,0x00ff00]" in MXML
          // set other styles here

          var columns:Array = new Array();
          var col:DataGridColumn = new DataGridColumn();
          col.headerText = "Test";
          col.dataField = "someField";
          columns.push(col);
          // create more columns

          grid.columns = columns; // same as <mx:columns> in MXML

          addChild(grid); // vital - without this your grid will not be visible.