1 Reply Latest reply on Feb 25, 2011 3:24 AM by miguel8312

    Cannot create property defaultColumnCount on mx.controls.DataGrid

    hidarikani Level 2

      The app compiles fine but an error occurs at runtime.



      <mx:DataGrid width="100%"



      Cannot create property defaultColumnCount on mx.controls.DataGrid


      Property description:

      http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/listClasses /ListBase.html#defaultColumnCount

        • 1. Re: Cannot create property defaultColumnCount on mx.controls.DataGrid
          miguel8312 Level 3

          it appears that datagrid does not inherite that property from listbase class or if it does its encapsulated so that is only used withing the class.

          what are you trying to do. when i look a the source code for flex datagrid i saw this.


          private var _columns:Array; // the array of our DataGridColumns
              [Inspectable(category="General", arrayType="mx.controls.dataGridClasses.DataGridColumn")]
               *  An array of DataGridColumn objects, one for each column that
               *  can be displayed.  If not explicitly set, the DataGrid control 
               *  attempts to examine the first data provider item to determine the
               *  set of properties and display those properties in alphabetic
               *  order.
               *  <p>If you want to change the set of columns, you must get this array,
               *  make modifications to the columns and order of columns in the array,
               *  and then assign the new array to the columns property.  This is because
               *  the DataGrid control returned a new copy of the array of columns and therefore
               *  did not notice the changes.</p>
               *  @langversion 3.0
               *  @playerversion Flash 9
               *  @playerversion AIR 1.1
               *  @productversion Flex 3
              override public function get columns():Array
                  return _columns.slice(0);
               *  @private
              override public function set columns(value:Array):void
                  var n:int;
                  var i:int;
                  n = _columns.length;
                  for (i = 0; i < n; i++)
                  freeItemRenderersTable = new Dictionary(false);
                  columnMap = {};
                  _columns = value.slice(0);
                  columnsInvalid = true;
                  generatedColumns = false;
                  n = value.length;
                  for (i = 0; i < n; i++)
                      var column:DataGridColumn = _columns[i];
                      column.owner = this;
                      column.colNum = i;
                      if (column.cachedHeaderRenderer)
                          var item:DisplayObject = column.cachedHeaderRenderer as DisplayObject
                          if (item.parent)
                          column.cachedHeaderRenderer = null;
                  fontContextChanged = true;
                  itemsSizeChanged = true;
                  dispatchEvent(new Event("columnsChanged"));



          its ovbious to me that flex is calculating how many columns will appear on the datagrid depending on the dataprovider you supply.

          Or if you would like to only show a specific amount of columns  you can futher define them in your grid like so




          <mx:DataGrid  id="grid" columnCount="2">
          <mx:DataGridColumn headerText="column1"/>
          <mx:DataGridColumn headerText="column2"/>   
            </mx:DataGrid >
          1 person found this helpful