I wrote very simple code to understand how columnstretch and calllater work but I couldn’t get resizeGrid function worked. What is going on here?
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var denemelist:ArrayCollection;
private function calculateHeight(l:int):Number{
return deneme.measureHeightOfItems(0, l) + deneme.headerHeight;
}
public function resizeGrid():void{
if(denemelist && deneme)
deneme.height = calculateHeight(denemelist.length);
}
public function preinit():void {
denemelist = new ArrayCollection([
{former:"sdfad", latter:"sdfgs"},
{former:"sdfgsd", latter:"sdfgsfd"}
]);
}
public function test():void {
denemelist.addItem({former:"sdfgsdf", latter:"sdfgdsgf"});
}
]]>
</mx:Script>
<mx:VBox width="100%" height="500">
<mx:DataGrid
width="100%"
resizeEffect="Resize"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
id="deneme"
variableRowHeight="true"
editable="false"
dataProvider="{denemelist}"
styleName="phrDataGrid"
columnStretch="callLater(resizeGrid)">
<mx:columns>
<mx:DataGridColumn dataField="former" headerText="former"/>
<mx:DataGridColumn dataField="latter" headerText="latter"/>
</mx:columns>
</mx:DataGrid>
<mx:Button label="deneme1" click="test()" />
</mx:VBox>
I don’t think the datagrid has been updated yet at the time that you’re calling the function. But you might try leaving off the height of the dg and then just setting the rowCount to the number of items in the list.
HTH;
Amy