posts - 325,  comments - 25,  trackbacks - 0
           

          15.項呈現器創建方法:

              1)內投方法:通過在列表控件的itemRenderer屬性中定義單個組件,能夠將插入的單個組件作為項呈現器

              2)內聯方法:使用列表控件的子標簽來定義一個或多個組件,這些組件將作為項呈現器

              3)可重用組件:將自定義組件作為項呈現器

          內投方法示例:

              

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

           <mx:Script>

           <![CDATA[

            

             [Bindable]

             privatevar myDP:Array = [

              {label: "Customer 1", selected: true},

              {label: "Customer 2", selected: false}

             ];

            

           ]]>

           </mx:Script>

           

           <mx:DataGrid dataProvider="{myDP}">

           <mx:columns>

             <mx:DataGridColumn dataField="label" headerText="Label" />

             <mx:DataGridColumn dataField="selected" itemRenderer="mx.controls.CheckBox" />

           </mx:columns>

           </mx:DataGrid>

           

          </mx:Application>

          內聯方法示例:

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

           <mx:Script>

           <![CDATA[

            

             [Bindable]

             privatevar myDP:Array = [

              {label: "Customer 1", selected: true},

              {label: "Customer 2", selected: false}

             ];

            

           ]]>

           </mx:Script>

           

           <mx:DataGrid dataProvider="{myDP}">

           <mx:columns>

             <mx:DataGridColumn dataField="label" headerText="Label" />

             <mx:DataGridColumn dataField="selected">

              <mx:itemRenderer>

               <mx:Component>

                <mx:VBox verticalAlign="middle" horizontalAlign="center">

                 <mx:CheckBox/>

                </mx:VBox>

               </mx:Component>

              </mx:itemRenderer>

             </mx:DataGridColumn>

           </mx:columns>

           </mx:DataGrid>

          </mx:Application>

          將組件作為呈現器示例:

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

           <mx:Script>

           <![CDATA[

            

             [Bindable]

             privatevar myDP:Array = [

              {label: "Oranges", date: new Date()},

              {label: "Apples", date: new Date()},

              {label: "Pears", date: new Date()}

             ];

            

           ]]>

           </mx:Script>

           

           <mx:List dataProvider="{myDP}" itemRenderer="MyCustomItemRenderer" />

           

          </mx:Application>

          MyCustomItemRenderer.xml

          <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">

           

           <mx:Script>

           <![CDATA[

             import mx.controls.Alert;

           ]]>

           </mx:Script>

           

           <mx:HBox>

           <mx:TextInput text="{data.label}" />

           <mx:DateField id="dateField" selectedDate="{data.date}" />

           <mx:Button label="Button" click="Alert.show('Selected item - Fruit: ' + data.label + '"n' + 'Date: ' + dateField.selectedDate)" />

           </mx:HBox>

          </mx:HBox>
          16.項編輯器
          編輯過程:
          a) 用戶利用鼠標按鈕或者tab鍵激活單元格
          b) 分派itemEditBeginning 事件,使用該事件能夠禁用某特定單元格或者多個單元格的編輯功能
          c) 分派itemEditBegin事件以便打開項編輯器,該事件可用于修改傳遞給項編輯器數據
          d)用戶編輯單元格數據
          e)用戶移除焦點時,結束編輯會話
          f)分派itemEditEnd 事件以便關閉項編輯器,同時使用新數據更新單元格

          當列表控件(List Tree DataGrid)的editable屬性設置為true時,用戶就能夠編輯控件內容

          自定義編輯事件監聽器訪問單元格數據:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

           <mx:Script>
            <![CDATA[
             import mx.controls.TextInput;
             import mx.events.DataGridEvent;
             import mx.collections.ArrayCollection;
             
             [Bindable]
             private var productsAC:ArrayCollection = new ArrayCollection
             (
              [
               {Product: "iPod", Price: 249},
               {Product: "iMac", Price: 1299},
               {Product: "MacBook Pro", Price: 1999}
              ]
             );
             
             private function getCellInfo(event:DataGridEvent):void
             {
              var myEditor:TextInput = TextInput(event.currentTarget.itemEditorInstance);
              var newVal:String = myEditor.text;
              var oldVal:String = event.currentTarget.editedItemRenderer.data[event.dataField];
              cellInfo.text = "cell edited. \n";
              cellInfo.text += "Row, column: " + event.rowIndex + ", " + event.columnIndex + "\n";
              cellInfo.text += "New value: " + newVal + "\n";
              cellInfo.text += "Old value: " + oldVal;
             }
             
            ]]>
           </mx:Script>
           
           <mx:TextArea id="cellInfo" width="300" height="150" />
           
           <mx:DataGrid dataProvider="{productsAC}" editable="true" itemEditEnd="getCellInfo(event)">
            <mx:columns>
             <mx:DataGridColumn dataField="Product" />
             <mx:DataGridColumn dataField="Price" />
            </mx:columns>
           </mx:DataGrid>
           
          </mx:Application>
          禁用單元格編輯器:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

           <mx:Script>
            <![CDATA[
             import mx.controls.TextInput;
             import mx.events.DataGridEvent;
             import mx.collections.ArrayCollection;
             
             [Bindable]
             private var productsAC:ArrayCollection = new ArrayCollection
             (
              [
               {Product: "iPod", Price: 249},
               {Product: "iMac", Price: 1299},
               {Product: "MacBook Pro", Price: 1999}
              ]
             );
             
             private function onEditBeginning(event:DataGridEvent):void
             {
              if (event.rowIndex == 2)
               event.preventDefault();
             }
             
            ]]>
           </mx:Script>
           
           <mx:DataGrid dataProvider="{productsAC}" editable="true" itemEditBeginning="onEditBeginning(event)">
            <mx:columns>
             <mx:DataGridColumn dataField="Product" />
             <mx:DataGridColumn dataField="Price" />
            </mx:columns>
           </mx:DataGrid>
           
          </mx:Application>



          posted on 2011-03-14 09:50 長春語林科技 閱讀(369) 評論(0)  編輯  收藏 所屬分類: flex
          <2011年3月>
          272812345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 宁国市| 临湘市| 长宁区| 阿坝县| 大宁县| 水城县| 修文县| 庆城县| 西宁市| 迁安市| 张掖市| 墨脱县| 泗水县| 伊春市| 云龙县| 成武县| 鹿泉市| 工布江达县| 榆中县| 临邑县| 佛教| 陆丰市| 望奎县| 吴忠市| 依安县| 巢湖市| 南澳县| 张北县| 陈巴尔虎旗| 三穗县| 安宁市| 清河县| 和顺县| 镇江市| 舟山市| 黑河市| 农安县| 大化| 类乌齐县| 临高县| 巴东县|