title: How to create a dynamic flex datagrid
body: <p>I'm trying to create a dynamic datagrid in Flex. The data is coming back fine and I can add the column headings. I need to do it this way as the column names are dynamic and coming from a mysql database.</p>
  
  <p>Can anyone help me get the values from re.result.resultSet.results[j].notes into the data fields?</p>
  
  <pre><code>   &lt;mx:Script&gt;
       &lt;![CDATA[
  
             import mx.rpc.events.FaultEvent;
             import mx.rpc.events.ResultEvent;
               import mx.controls.Alert;
               import mx.controls.dataGridClasses.DataGridColumn; 
  
  
              public function faultHandler(event:FaultEvent ):void {
                  // The following statements must be inside a function. 
  
                  text.text = event.message.toString();
              }
              public function resultHandler(re:ResultEvent):void {
                  // The following statements must be inside a function. 
  
                  text.text = "blah";
                  text.text += re.result.resultSet.columnList[0].key.toString();
  
  
                  for (var i:int = 0; i&lt; re.result.resultSet.columnList.length; i++) {
                      text.text += re.result.resultSet.columnList[i].key.toString();
  
                  }
                  var cols:Array = new Array();
                  var dataProv:Array = new Array();
                  for (var j:int = 0; j&lt; re.result.resultSet.columnList.length; j++) {
                      text.text += re.result.resultSet.results[j].notes.toString();
                      var column:DataGridColumn = new DataGridColumn;
                      column.headerText= re.result.resultSet.results[j].label.toString();
                      column.dataField = re.result.resultSet.results[j].notes.toString();
                      cols.push(column);
  
  
              }
              myGrid.columns = cols;
  
  
              }
  
  
  
      ]]&gt;&lt;/mx:Script&gt;
       &lt;mx:TextArea id="text" x="74" y="47" width="551" height="350"/&gt;
       &lt;mx:Button x="647" y="46" label="Button" click ="{myservice.getWorkSheets()}"/&gt;
      &lt;mx:DataGrid id="myGrid" x="74" y="424" width="551"/&gt;
  
  &lt;/mx:Application&gt;
  </code></pre>
  
  <p>thanks,</p>