2013-03-20 117 views
0

我有一個自定義的DataGrid,我想添加自定義菜單:添加自定義菜單項的DataGrid

public function MyCustomDataGrid() { 
    super(); 
    init(); 
} 

private function init():void { 
    var _copyElementMenuItem:ContextMenuItem = new ContextMenuItem("Copier Donnée"); 
    _copyElementMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleCopyData); 

    this.contextMenu = new ContextMenu(); 
    contextMenu.hideBuiltInItems(); 
    contextMenu.customItems = [ _copyElementMenuItem ]; 
} 

的問題是,我的自定義菜單項就不會顯示了,我永諾結束了標準閃存上下文菜單:

enter image description here

我缺少什麼?我該如何解決這個問題?謝謝。

回答

1

它適用於我。看看我的代碼。

enter image description here

//應用

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      minWidth="955" minHeight="600" xmlns:custommenu="com.custommenu.*"> 
<fx:Script> 
    <![CDATA[ 
     import mx.collections.ArrayCollection; 

     [Bindable]private var collection:ArrayCollection = new ArrayCollection([ 
      {field01:"field01", field02:"field02"}, 
      {field01:"field01", field02:"field02"} 
     ]); 

    ]]> 
</fx:Script> 
<s:VGroup x="20" y="20"> 
    <custommenu:MyCustomDataGrid 
     dataProvider="{collection}" 
     width="200" height="100"> 
     <custommenu:columns> 
      <s:ArrayList> 
       <s:GridColumn dataField="field01" headerText="Field 1"/> 
       <s:GridColumn dataField="field02" headerText="Field 2"/> 
      </s:ArrayList>     
     </custommenu:columns>   
    </custommenu:MyCustomDataGrid> 
</s:VGroup> 
</s:Application> 

// MyCustomDataGrid

<?xml version="1.0" encoding="utf-8"?> 
<s:DataGrid xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" 
     creationComplete="init()"> 
<fx:Script> 
    <![CDATA[ 
     import mx.controls.Alert; 

     protected function init():void 
     { 
      var _copyElementMenuItem:ContextMenuItem = new ContextMenuItem("Copier Donnée"); 
      _copyElementMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleCopyData); 

      this.contextMenu = new ContextMenu(); 
      contextMenu.hideBuiltInItems(); 
      contextMenu.customItems = [ _copyElementMenuItem ]; 
     } 

     private function handleCopyData(evt:ContextMenuEvent):void 
     { 
      Alert.show("Hello!"); 
     } 

    ]]> 
</fx:Script> 

</s:DataGrid> 
相關問題