출처 : http://www.ihelpers.co.kr/programming/tipntech.php?CMD=view&TYPE=8&KEY=&SC=S&&CC=&PAGE=1&IDX=547

1.데모

2. 소스

MiyaGrid.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="absolute" xmlns:ns1="*" creationComplete="initApp()" viewSourceURL="srcview/index.html" fontSize="12">
 <mx:Script>
  <![CDATA[
   import mx.controls.dataGridClasses.DataGridColumn;
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   
   [Bindable]
   private var ArrCol:ArrayCollection = new ArrayCollection();
   
   
   public function initApp():void{    
    myGrid.dataProvider = ArrCol;    
   }
   
   public function onChangeColumn():void{
   
    // Grid init
    myGrid.columns = [];
    ArrCol.removeAll();
    var arrCol:Array = new Array();
   
    for(var i:uint = 0; i<chgColumn.value;i++){
     var col:DataGridColumn = new DataGridColumn("col"+i);
     var colRender:ClassFactory = new ClassFactory(LabelRenderer);    
     colRender.properties = {headerText:"컬럼"+i};
     col.headerRenderer = colRender;  
     col.setStyle("textAlign","right");
     arrCol.push(col);
    }
    myGrid.columns = arrCol;  
   
    for(i=0;i<100;i++){
     var colval:Object = new Object;
     for(var j:uint = 0; j<chgColumn.value;j++){
      colval["col"+j] = (i+1)*(j+1);
     }
     ArrCol.addItem(colval);
    } 
   }
  ]]>
 </mx:Script>
 <mx:Component id="HeaderLabelRenderer">  
     <mx:HBox horizontalAlign="left" verticalAlign="middle">
     <mx:Label text="" textIndent="3" width="100%" textAlign="left"/>
     </mx:HBox>
 </mx:Component>
 <mx:DataGrid left="10" right="10" top="70" bottom="10" id="myGrid" fontSize="12"/>
 <mx:HBox left="10" right="10" top="10" bottom="518">
  <mx:Form width="100%">
   <mx:FormItem label="컬럼수">
    <mx:HSlider id="chgColumn" width="236" minimum="5" maximum="10" snapInterval="1" enabled="true" change="onChangeColumn()"/>
   </mx:FormItem>
  </mx:Form>
 </mx:HBox>
</mx:Application>

LabelRenderer.mxml

Grid HeaderText 값을 동적으로 사용하기 위해 headerText 사용하였습니다.

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
  horizontalAlign="left" verticalAlign="middle" horizontalScrollPolicy="off" creationComplete="initComp()">
     <mx:Script>
      <![CDATA[

   private var _headerText:String;
   
   public function set headerText(value:String):void {
    _headerText = value;
   }
   
   public function get headerText():String {
    return _headerText;
   }

       public function initComp():void {
        lvlLabel.text = _headerText;  
       }
        ]]>
     </mx:Script>
     <mx:Label text="" textIndent="3" width="100%" textAlign="left" id="lvlLabel"/>
</mx:HBox>


3. 참고

Posted by 나비:D
:
BLOG main image
by 나비:D

공지사항

카테고리

분류 전체보기 (278)
Programming? (0)
---------------------------.. (0)
나비의삽질 (5)
Application (177)
SQL (51)
Web (27)
etc. (14)
Omnia (0)
---------------------------.. (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

달력

«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Total :
Today : Yesterday :