1 Reply Latest reply on Dec 6, 2007 5:28 PM by rvollmar

          Specifying class properties in MXML elements instead of attributes (e.g. DataGridColumns)

    Joubert Nel
      Hi there,

      In all the examples I've seen so far, specifying the columns for a
      DataGrid is done as follows:

      <mx:DataGrid>
      <mx:columns>
      <mx:DataGridColumn />
      <mx:DataGridColumn />
      <mx:columns>
      </mx:DataGrid>

      However, I'm wonder whether there's a way to express the data grid
      columns simply as an _attribute_ value on the <mx:DataGrid> element?

      If not, does anybody know of an explanation of the syntax for setting
      class properties when they are not set as attributes?

      For example, since "columns" is a property of the DataGrid class, but
      it is set via an XML element, and not via an XML attribute, I would
      assume you can do something similar for other properties. However, I
      can't seem to find official documentation on this in the Flex 3
      Language Reference.

      Joubert
        • 1. Re:       Specifying class properties in MXML elements instead of attributes (e.g. DataGridColumns)
          rvollmar
          This works:


          <mx:Array id="theMXMLColumns">
          <mx:DataGridColumn headerText="Column 1" />
          <mx:DataGridColumn headerText="Column 2" />
          </mx:Array>

          <mx:DataGrid id="dg2" columns="{theMXMLColumns}" />

          However, the "columns" property of DataGrid must be an array, and arrays are not bindable, so ActionScript updates to the array would not be shown. e.g. This will not work:


          <mx:Script>
          <![CDATA[
          import mx.collections.*;
          import mx.controls.dataGridClasses.*;

          private var theASColumns:Array;

          private function doCreationComplete():void{
          var dgc:DataGridColumn;

          theASColumns = new Array();

          dgc = new DataGridColumn();
          dgc.headerText = "Column 1";
          theASColumns.push(dgc);

          dgc = new DataGridColumn();
          dgc.headerText = "Column 2";
          theASColumns.push(dgc);
          }
          ]]>
          </mx:Script>

          <mx:DataGrid id="dg" columns="{theASColumns}" />