Friday, April 3, 2009

Changing the headers of dataGrid dynamically

In a recent project I was working on, I came across a situation where I will know the header text for the columns at run time, pulled from a xml document.

And here is how I did it.


private function setHeaderTexts():void {
var i:Number = 0;
var columns:ArrayCollection =new ArrayCollection(datagrid.columns);
for each (var column:DataGridColumn in columns) {
column.headerText = tempArrayCollection.getItemAt(i).toString();
//tempArrayCollection is where I store the list of headers from the XML
i++;
}
datagrid.invalidateDisplayList();
}


Hope it helps!

Bookmark and Share

No comments: