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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 南召县| 木兰县| 徐闻县| 富民县| 内乡县| 来安县| 河西区| 望城县| 游戏| 洪泽县| 荣成市| 汉川市| 弥渡县| 思茅市| 安康市| 于田县| 札达县| 灌阳县| 咸丰县| 苍南县| 通化县| 台南市| 香格里拉县| 肇庆市| 衡阳县| 焉耆| 绵阳市| 高邮市| 铜川市| 辽源市| 陆良县| 武清区| 霞浦县| 阳朔县| 玛沁县| 塘沽区| 景谷| 迁西县| 津南区| 朝阳市| 龙泉市|