Hello, I am trying to create a grid that will update its size on a column resize event. I want the grid to keep getting large until they hit a max width then turn on a horizontal scroll bar.
Everything seems to work fine unless I have a vertical scroll bar present in the grid. When I try to re-size a column the datagrid adds a horizontal scroll bar automatically. Heres my code: <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()" viewSourceURL="srcview/index.html"> <mx:Script> <![CDATA[ import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn; import mx.controls.advancedDataGridClasses.AdvancedDataGridRendererProvider; import mx.events.IndexChangedEvent; import mx.events.ResizeEvent; import mx.collections.IViewCursor; import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; import mx.events.DataGridEvent; import mx.events.AdvancedDataGridEvent; import mx.controls.dataGridClasses.DataGridColumn; import mx.managers.CursorManager; public var bDummy:Boolean = false; [Bindable] private var itemAC:ArrayCollection; private function initApp():void{ dg.maxWidth = stuff.width; dg.addEventListener(AdvancedDataGridEvent.COLUMN_STRETCH, resizeCol); } private function resizeCol(event:AdvancedDataGridEvent):void { var _colIndex:Number = event.columnIndex; var width:Number; for(var i:int = 0; i <= dg.columns.length - 1; i++) { width += dg.columns[i].width; } dg.width = width; //ive tried to add 18 here to handle the scroll bar but then the maxWidth //is ignored and the grid keeps resizing outside of its maxWidth } ]]> </mx:Script> <mx:Array id="arr"> <mx:Object name="Redsox" quanity="10" cost="1000"/> <mx:Object name="Rays" quanity="11" cost="500"/> <mx:Object name="Yankees" quanity="20" cost="2000"/> </mx:Array> <mx:Canvas width="500" height="45%" backgroundColor="red" horizontalCenter="0" verticalCenter="-65" id="stuff" verticalScrollPolicy="off" horizontalScrollPolicy="off"> <mx:AdvancedDataGrid width="318" height="80" id="dg" horizontalCenter="0" dataProvider="{arr}" horizontalScrollPolicy="auto" > <mx:columns> <mx:AdvancedDataGridColumn width="100" headerText="name" dataField="name"/> <mx:AdvancedDataGridColumn width="100" headerText="quanity" dataField="quanity"/> <mx:AdvancedDataGridColumn width="100" headerText="cost" dataField="cost"/> </mx:columns> </mx:AdvancedDataGrid> </mx:Canvas> </mx:Application>