Adapt Flex Datagrid height to content

By | 9 March, 2011

This is a fix for a recurring problem. When we want to make the datagrid’s height to cover its content (dataprovider).

<mx:DataGrid xmlns:mx=””
variableRowHeight=”true” verticalScrollPolicy=”off” wordWrap=”true” rowCount=”{dataProvider.length}”
dataChange=”resize()” columnStretch=”resize()” resize=”resize()” >


//This is a work around for the poorly designed wordWrap and variableRowHeight features of the DataGrid
private function resize():void
if (dataProvider)
var h:Number = measureHeightOfItems( -1, dataProvider.length + 1);
if (h > maxHeight && maxHeight != 0)
verticalScrollPolicy = “on”;
h = maxHeight;
verticalScrollPolicy = “off”;
this.height = h;


Got it from here:

<a href=”″ target=”_blank” ></a>