1 Reply Latest reply on Jan 27, 2010 12:43 PM by olegkon

    AS3: Dynamic XMLListCollection

    olegkon Level 1

      Hi,

       

      I am writing AIR app emulating Excel 2007.

       

      Trying to initialize a DataGrid dataProvider, which is XMLListCollection.

      Need to create something like that:

      <root>

      <row><A/><B/><C/>...</row>

      ...

      </root>

      But the number of rows and columns should be paramatrized like:

       

      private function initDG(colNum:int, rowNum:int):void {

       

      if (!gridData)
           gridData = new XMLListCollection();

       

      for (var j:int=0; j < rowNum; j++) {                   
          for (var i:int=0; i < colNum; i++) {                  

                // WHAT should be here to initialize every element of XMLListCollection ???         
               //gridData.addItem({<row><A/><B/><C/><D/><E/></row>}); // that obviously doesn't work  
          }

      }

      grid.dataProvider = dataGrid;

      this.addChild(grid);         

       

      }

       

       

      TIA,

      Oleg.

        • 1. Re: AS3: Dynamic XMLListCollection
          olegkon Level 1

          To answer my question the initialization loop should be something like that:

          for (var j:int=0; j < rowNum; j++) {
                rowXML = <row/>;
                for (var i:int=0; i < colNum; i++) {    // init each DG cell to "" (i.e. like: <A/>)                      
                    rowXML.appendChild(new XML("<"+colNames[i]+"/>"));
                }                                       
               gridData.addItem(rowXML);
          }

           

          Thanks,

          Oleg.