Monday, March 22, 2010

column color change at runtime

hi,

聽聽聽聽聽 how to change the column color in datagrid at runtime after bind the data into the grid.kindly tell me which event i would like to handle .

thanks

Woodson.

column color change at runtime

Hi

You can listen for changes to the datagrids dataProvider, and reacting to that, set the backGround color using the style property for the column.

%26lt;?xml version=''1.0'' encoding=''utf-8''?%26gt;
%26lt;mx:Application xmlns:mx=''http://www.adobe.com/2006/mxml'' layout=''absolute'' creationComplete=''handleCreation()'' %26gt;
聽聽聽 %26lt;mx:Script%26gt;
聽聽聽聽聽聽聽 %26lt;![CDATA[
聽聽聽聽聽聽聽聽聽聽聽 import mx.events.CollectionEvent;
聽聽聽聽聽聽聽聽聽聽聽 import mx.collections.ArrayCollection;
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 private var myArray:Array = new Array({name :'Chris'});
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 [Bindable]
聽聽聽聽聽聽聽聽聽聽聽 private var ac:ArrayCollection = new ArrayCollection([
聽聽聽聽聽聽聽聽聽聽聽 {name : 'Andrew'}]);
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 private function handleCreation():void {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ac.addEventListener(CollectionEvent.COLLECTION_CHANGE, handleDataChange);
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 private function handleDataChange(event:CollectionEvent):void {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 col1.setStyle('backgroundColor',0xe5e5e5);
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 private function changeData():void {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ac.source = myArray;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 ]]%26gt;
聽聽聽 %26lt;/mx:Script%26gt;
聽聽聽
聽聽聽 %26lt;mx:DataGrid id=''dg'' x=''101'' y=''112'' dataProvider=''{ac}''%26gt;
聽聽聽聽聽聽聽 %26lt;mx:columns%26gt;
聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn id=''col1'' headerText=''name'' dataField=''name'' /%26gt;
聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn headerText=''Column 2'' dataField=''col2''/%26gt;
聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn headerText=''Column 3'' dataField=''col3''/%26gt;
聽聽聽聽聽聽聽 %26lt;/mx:columns%26gt;
聽聽聽 %26lt;/mx:DataGrid%26gt;
聽聽聽 %26lt;mx:Button x=''101'' y=''288'' label=''Change Data'' click=''changeData()''/%26gt;
聽聽聽
%26lt;/mx:Application%26gt;

Hope that helps.

Andrew

No comments:

Post a Comment