ValueCommit probably isn’t the right event.  The DG probably doesn’t have the 
final width yet so the heights will not calculate correctly.  Maybe try 
updateComplete.  Also, you are not factoring in viewMetrics.top/bottom.


On 3/16/10 8:08 AM, "atomilux" <atomi...@yahoo.com> wrote:






Here's an example. I've tried a plethora of events and some of them are worse 
than others. Reordering inside each DataGrid seems to fire it correctly. I'm 
guessing there is a data update behind the scenes that might not be 100% done 
before the event fires:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute"
creationComplete="init()">
<mx:Script>
<![CDATA[

import mx.collections.ArrayCollection;

public var derXML:XML = <root>
<category order="0" x="0" y="0" width="200" height="200">
<name>Category 1</name>
<item order="0">
<text>Some item number 1 in cat 1</text>
</item>
<item order="1">
<text>Some item number 2 in cat 1</text>
</item>
<item order="2">
<text>Some item number 3 in cat 1</text>
</item>
<item order="3">
<text>Some item number 4 in cat 1</text>
</item>
<item order="4">
<text>Some item number 5 in cat 1</text>
</item>
</category>
</root> ;

public var derXML2:XML = <root>
<category order="0" x="0" y="0" width="200" height="200">
<name>Category 2</name>
<item order="0">
<text>Some item number 1 in cat 2</text>
</item>
<item order="1">
<text>Some item number 2 in cat 2</text>
</item>
<item order="2">
<text>Some item number 3 in cat 2</text>
</item>
<item order="3">
<text>Some item number 4 in cat 2</text>
</item>
<item order="4">
<text>Some item number 5 in cat 2</text>
</item>
</category>
</root> ;

[Bindable] var derData:ArrayCollection;
[Bindable] var derData2:ArrayCollection;

public function init():void {

buildMXMLfromXML();

}//end func

public function buildMXMLfromXML():void {

var categoriesXML:XML = derXML.category.(@order == 0)[0];
var categoriesXML2:XML = derXML2.category.(@order == 0)[0];

//get the items for this category
var itemList:XMLList = categoriesXML.item;
var itemList2:XMLList = categoriesXML2.item;

derData = new ArrayCollection();
derData2 = new ArrayCollection();

for (var j:uint=0;j<itemList.length();j++) {
derData.addItem({item:itemList[j].text.toString()});
}//end for

for (var j:uint=0;j<itemList2.length();j++) {
derData2.addItem({item:itemList2[j].text.toString()});
}//end for

mainDataGrid.dataProvider = derData;
mainDataGrid2.dataProvider = derData2;

}//end function buildMXMLfromXML()

public function updateDGheight(evt:Event):void {

var tmpDG:DataGrid = evt.currentTarget as DataGrid;
var measureHeight:Number =
tmpDG.measureHeightOfItems(-1,tmpDG.dataProvider.length);
tmpDG.height = measureHeight;

}//end function

]]>
</mx:Script>
<mx:VBox width="800">
<mx:Box id="category1" width="100%">

<mx:DataGrid id="mainDataGrid"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
editable="{mx.core.Application.application.editMode}"
allowDragSelection="true"
verticalScrollPolicy="off"
variableRowHeight="true"
valueCommit="{updateDGheight(event)}"

width="100%"
showHeaders="false"
alternatingItemColors="#FFFFFF"
borderThickness="0"
verticalGridLines="false"
rollOverColor="#AAA9A9">
<mx:columns>

<!-- Text -->
<mx:DataGridColumn dataField="item" paddingLeft="5" wordWrap="true"/>

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

</mx:Box><!-- end category 1 -->

<mx:Box id="category2" width="100%">

<mx:DataGrid id="mainDataGrid2"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
editable="{mx.core.Application.application.editMode}"
allowDragSelection="true"
verticalScrollPolicy="off"
variableRowHeight="true"
valueCommit="{updateDGheight(event)}"

width="100%"
showHeaders="false"
alternatingItemColors="#FFFFFF"
borderThickness="0"
verticalGridLines="false"
rollOverColor="#AAA9A9">
<mx:columns>

<!-- Text -->
<mx:DataGridColumn dataField="item" paddingLeft="5" wordWrap="true"/>

</mx:columns>
</mx:DataGrid>
</mx:Box><!-- end category 2 -->

</mx:VBox>

</mx:Application>

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , Alex 
Harui <aha...@...> wrote:
>
> Renderers are recycled and kept on the display list with visible=false.  I 
> don't know of any bugs related to that.  Older versions of flex had some bugs 
> around measureHeightOfItems.  There might still be bugs but make sure you're 
> on the latest.
>
> Most commonly, custom renderers don't handle recycling and do not measure 
> correctly, throwing off the result of measureHeightOfItems.
>
> If you have a simple test case, post it or file a bug.
>
> Alex Harui
> Flex SDK Developer
> Adobe Systems Inc.<http://www.adobe.com/>
> Blog: http://blogs.adobe.com/aharui






--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui

Reply via email to