Tempo

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            1 Posts :: 6 Stories :: 0 Comments :: 0 Trackbacks

          廢話不說,看代碼:
          package
          {
          import flash.display.Sprite;

          import mx.controls.DataGrid;

          public class RowColorDataGrid extends DataGrid
          {
          public function RowColorDataGrid()
          {
          super();
          }

          override protected function drawRowBackground(s:Sprite,rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void{
          if(dataIndex<super.dataProvider.length){
          super.drawRowBackground(s, rowIndex, y, height, 0x49FFAD, dataIndex);
          }else{
          super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
          }
          }
          }
          }

          先自定義一個DataGrid類,該類繼承自DataGrid類。然后在自己的代碼中引用該類即可,如下:
          <?xml version="1.0"?>
          <!-- DataGrid control example. -->
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:probe="*">

          <mx:XMLList id="employees">
          <employee>
          <name>Christina Coenraets</name>
          <phone>555-219-2270</phone>
          <email>ccoenraets@fictitious.com</email>
          <active>true</active>
          </employee>
          <employee>
          <name>Joanne Wall</name>
          <phone>555-219-2012</phone>
          <email>jwall@fictitious.com</email>
          <active>true</active>
          </employee>
          <employee>
          <name>Maurice Smith</name>
          <phone>555-219-2012</phone>
          <email>maurice@fictitious.com</email>
          <active>false</active>
          </employee>
          <employee>
          <name>Mary Jones</name>
          <phone>555-219-2000</phone>
          <email>mjones@fictitious.com</email>
          <active>true</active>
          </employee>
          </mx:XMLList>

          <mx:Panel title="行著色DataGrid" height="100%" width="100%"
          paddingTop="10" paddingLeft="10" paddingRight="10">
          <probe:RowColorDataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{employees}">
          <probe:columns>
          <mx:DataGridColumn dataField="name" headerText="Name"/>
          <mx:DataGridColumn dataField="phone" headerText="Phone"/>
          <mx:DataGridColumn dataField="email" headerText="Email"/>
          </probe:columns>
          </probe:RowColorDataGrid>

          <mx:Form width="100%" height="100%">
          <mx:FormItem label="Name">
          <mx:Label text="{dg.selectedItem.name}"/>
          </mx:FormItem>
          <mx:FormItem label="Email">
          <mx:Label text="{dg.selectedItem.email}"/>
          </mx:FormItem>
          <mx:FormItem label="Phone">
          <mx:Label text="{dg.selectedItem.phone}"/>
          </mx:FormItem>
          </mx:Form>

          </mx:Panel>
          </mx:Application>
          文章來源:http://probe.javaeye.com/blog/481709
          posted on 2009-10-05 12:14 Tempo 閱讀(589) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 高雄县| 开江县| 新龙县| 太和县| 郸城县| 顺昌县| 奈曼旗| 宣汉县| 绍兴市| 荥经县| 元氏县| 嵩明县| 农安县| 册亨县| 扬中市| 宜宾市| 长顺县| 比如县| 凭祥市| 保亭| 贡觉县| 五家渠市| 邢台市| 伽师县| 汉阴县| 涟源市| 泰顺县| 黄浦区| 阿拉尔市| 长沙市| 扬州市| 花莲市| 龙门县| 扎赉特旗| 东乡族自治县| 茌平县| 乾安县| 聊城市| 德阳市| 隆化县| 如东县|