当数据很多的时候
Flex Datagrid 会自动给表格加上滚动条
有时候我们需要去除滚动条 如何做呢?
添加对窗体的updateComplete 或者createComplte事件
或者对dataGrid的dataprovider添加监听事件
后者会占用占用稍微少一点的资源
然后对datagrid的高度赋值
dg.height = dg.measureHeightOfItems(0, dgDataProvider.length) + dg.headerHeight
<mx:vbox xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:script> <!–[CDATA[ import mx.collections.ArrayCollection; [Bindable]–> public var text:String = ""; [Bindable] public var gridData:ArrayCollection; public function handleCreationComplete(e:Event):void { trace("finished"); //+2 for 1 pixel border at top and bottom dg.height=dg.measureHeightOfItems(0,gridData.length)+dg.headerHeight+2; } ]]> </mx:script> <mx:datagrid id="dg"> editable="true" variableRowHeight="true" width="460" dataProvider="{gridData}" creationComplete="handleCreationComplete(event)"> <mx:columns> <mx:datagridcolumn datafield="name" headertext="Name"> <mx:datagridcolumn datafield="phone" headertext="Phone"> <mx:datagridcolumn datafield="email" headertext="Email"> </mx:datagridcolumn> </mx:datagridcolumn> </mx:datagridcolumn> </mx:columns> </mx:datagrid> </mx:vbox>
参考实例