Did you try doing DataGrid(gridId).setActualSize(); or just extend the 
dataGridColumn and override the mx_internal that calculates the width.



----- Original Message ----
From: brileach <[EMAIL PROTECTED]>
To: flexcoders@yahoogroups.com
Sent: Wednesday, January 16, 2008 2:50:30 PM
Subject: [flexcoders] DataGrid column resizing

I've been slamming my head against my desk for the last day trying to
figure out how to resize DataGrid columns and I'm hoping somebody can
help me out. I'm using Flex 2.0.1. Any help will be much appreciated!

The idea here is that onCreationComplete the DataGridColumns will
recreate themselves based off of a certain size, eventually the length
of the data inside of them. I've gotten this to work with every
attribute except width. (labelFunctions, itemRenderers, etc.)

<mx:Script>
<![CDATA[

private var gridData:Array = [
{ symbol: "ADBE", name: "Adobe Systems Inc.", price: 49.95 },
{ symbol: "MACR", name: "Macromedia Inc.", price: 39.95 },
{ symbol: "MSFT", name: "Microsoft Corp.", price: 25.95 },
{ symbol: "IBM", name: "IBM Corp.", price: 42.55 }
];

public function resizeGridColumns( gridId:Object) :void {
var oldColumns:Array = gridId.columns;
var numberOfColumns: int = oldColumns.length;
var newColumns:Array = new Array();
for(var i:int = 0; i < numberOfColumns; i++){
var oldColumn:DataGridC olumn = (oldColumns[ i] as DataGridColumn) ;
var newColumn:DataGridC olumn = new DataGridColumn;
newColumn.dataField = oldColumn.dataField ;
newColumn.headerTex t = oldColumn.headerTex t+"-dynamic" ;
newColumn.width = 50;
newColumns.push( newColumn) ;
}
gridId.columns = newColumns;
}

]]>
</mx:Script>

<mx:DataGrid id="grid" 
initialize=" grid.dataProvide r = gridData" 
creationComplete= "resizeGridColum ns(grid)"
width="500">
<mx:columns>
<mx:DataGridColumn headerText=" Name" dataField="name" />
<mx:DataGridColumn headerText=" Symbol" dataField="symbol" />
<mx:DataGridColumn headerText=" Price" dataField="price" />
</mx:columns> 
</mx:DataGrid>

I just can't figure out how to set a column width on the fly. 

Thanks!

--Brian Leach, [EMAIL PROTECTED] com





      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

Reply via email to