0 Replies Latest reply on Apr 27, 2007 1:07 PM by BellCurve

    Dynamicly resizing the DataGrid control

    BellCurve
      I'm trying to get the height of my DataGrid to resize based on the number of items in the grid.

      Any help on this is apprecaiated.

      I'm trying to resize a datagrid based on its cell contents. So far I've tried the following approach with several several different events, but I'm not having any luck.




      <?xml version="1.0" encoding="iso-8859-1"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:local="*">
      <mx:Script>
      <![CDATA[
      [Bindable]
      private var example:XML =
      <root>
      <row>
      <value>1</value>
      </row>
      <row>
      <value>2</value>
      </row>
      <row>
      <value>3</value>
      </row>
      <row>
      <value>4</value>
      </row>
      <row>
      <value>5</value>
      </row>
      <row>
      <value>6</value>
      </row>
      </root>;

      [Bindable]
      private var dgsize:Number;

      private function sizeGrid(count:Number, height:Number):Number
      {
      count = myDataGrid.rowCount;
      height = myDataGrid.rowHeight;
      trace("count: " + count);
      trace("height: " + height);
      dgsize = (count * height) /2;
      trace (dgsize);
      return dgsize;

      }

      ]]>
      </mx:Script>
      <mx:DataGrid id="myDataGrid" height="433"
      dataProvider="{example.row}"
      variableRowHeight="false" enabled="true" width="800" creationComplete="{sizeGrid(myDataGrid.rowCount,myDataGrid.rowHeight)}">
      <mx:columns>
      <mx:DataGridColumn headerText="Row Count" dataField="value"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:Application>