Try the measureText function. Multplying by 10 is probably overkill.
What else is in the HBox with the DG? Maybe you don't want a hscrollbar there. ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of akhilesh_iet Sent: Tuesday, December 25, 2007 11:21 PM To: [email protected] Subject: [flexcomponents] Re: Dynamically rendering the data grid I already tried this option (horizontalScrollPolicy="on")but the problem is that I have this data grid in a HBox and this (horizontalScrollPolicy="on") puts scroller in both (data grd and in HBox). I am multiplying it by 10 to caluculate the width of a particular column. If i am not doing this ( multiplying by 10) .. Grid col names are not displayed properly. --- In [email protected] <mailto:flexcomponents%40yahoogroups.com> , "Alex Harui" <[EMAIL PROTECTED]> wrote: > > At init time, the size of the DG is not known so you get to dictate it > with the column widths, then all columns get resized proportionally. > After that it is sort of locked in so columns sizes are honored except > those at the end that will get squished to fit. If you set > horizontalScrollPolicy="on" it won't resize the columns. > > Why are you multiplying by 10? > > ________________________________ > > From: [email protected] <mailto:flexcomponents%40yahoogroups.com> > [mailto:[email protected] <mailto:flexcomponents%40yahoogroups.com> ] On Behalf Of akhilesh_iet > Sent: Sunday, December 09, 2007 11:16 PM > To: [email protected] <mailto:flexcomponents%40yahoogroups.com> > Subject: [flexcomponents] Dynamically rendering the data grid > > > > In my project i have a requirement where i need to render the > datagrid, the number( and names) of columns that need to be > displayed will be provided at run time. I have created a sample > application to acheive the same, but i am facing the problem ( last > 3-4 columns do not show up properly ) while rendring the grid for > second time. Here is the code :' > <?xml version="1.0"?> > <!-- DataGrid control example. --> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > " > initialize="initializeHandler(event)"> > <mx:Script> > <![CDATA[ > import mx.collections.ArrayCollection; > private function initializeHandler > (event:Event):void { > > var arrayList:ArrayCollection = new > ArrayCollection(); > var fieldData:Array = new Array(); > for ( var i:int = 0 ; i < 8 ; i ++){ > fieldData = new Array(8); > for ( var j:int = 0 ; j < > 8 ; j++){ > fieldData[j] > = "column " + i + ", " + j; > } > arrayList.addItem(fieldData); > } > kapil.dataProvider = arrayList; > kapil.invalidateDisplayList(); > > for ( j = 0 ; j < 8 ; j++){ > > > kapil.columns > [j].headerText = "ColumnHeaderText " + j; > kapil.columns > [j].width = kapil.columns[j].headerText.toString().length * 10; > } > > } > > private function kapili(event:Event):void{ > var arrayList:ArrayCollection = new > ArrayCollection(); > kapil.dataProvider = arrayList; > var fieldData:Array = new Array(); > for ( var i:int = 0 ; i < 8 ; i ++){ > fieldData = new Array(8); > for ( var j:int = 0 ; j < > 8 ; j++){ > fieldData[j] > = "column " + i + ", " + j; > } > arrayList.addItem(fieldData); > } > kapil.dataProvider = arrayList; > kapil.invalidateDisplayList(); > > for ( j = 0 ; j < 8 ; j++){ > kapil.columns[j].headerText > = "ColumnHeaderText " + j; > kapil.columns[j].width = > kapil.columns[j].headerText.toString().length * 10; > } > > } > ]]> > </mx:Script> > > <mx:DataGrid id="kapil" /> > <mx:Button label="Button" click="kapili(event)"/> > </mx:Application> > > please provide your comments ASAP. > > regards > Akhilesh >
