主頁 > 知識(shí)庫 > 在Flex中給datagrid添加右鍵菜單項(xiàng)的具體實(shí)現(xiàn)

在Flex中給datagrid添加右鍵菜單項(xiàng)的具體實(shí)現(xiàn)

熱門標(biāo)簽:地圖標(biāo)注多家店 南昌crm外呼系統(tǒng)如何 外呼系統(tǒng)號(hào)碼顯示 車載電話機(jī)器人 天津企業(yè)外呼系統(tǒng)代理商 無錫電銷外呼系統(tǒng)代理 什么行業(yè)需要電話機(jī)器人 廣州ai外呼系統(tǒng)業(yè)務(wù) 中山外呼系統(tǒng)中間件
復(fù)制代碼 代碼如下:

?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"
creationComplete="initApp()">
s:layout>
s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
/s:layout>
fx:Script>
![CDATA[
import mx.controls.Alert;
import mx.events.DataGridEvent;
import mx.events.FlexEvent;

import spark.events.GridEvent;
private var myContextMenu:ContextMenu;

private function initApp():void
{
popUpMenu();
}

private function popUpMenu():void
{
myContextMenu = new ContextMenu();
removeDefaultItems();
addCustomMenuItems();
//監(jiān)聽右鍵菜單彈出后的事件
myContextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, menuSelectedHandler);
myDataGrid.contextMenu = myContextMenu;
}
//刪除原有菜單項(xiàng)
private function removeDefaultItems():void
{
myContextMenu.hideBuiltInItems();
var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
defaultItems.print = false;
}
//添加用戶自定義菜單項(xiàng)
private function addCustomMenuItems():void
{
var item:ContextMenuItem = new ContextMenuItem("刪除行");
//默認(rèn)的菜單項(xiàng)
item.visible = false;
myContextMenu.customItems.push(item);
//監(jiān)聽選擇菜單項(xiàng)后的事件
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, itemSelectedHandler);
}
//彈出菜單后的事件處理函數(shù)
private function menuSelectedHandler(event:ContextMenuEvent):void
{
var item:ContextMenuItem = myContextMenu.customItems[0] as ContextMenuItem;

if (myDataGrid.selectedIndex >= 0)
{
item.visible = true;
}
else
{
item.visible = false;
}
}
//選擇菜單項(xiàng)后的事件處理函數(shù)
private function itemSelectedHandler(event:ContextMenuEvent):void
{

if (myDataGrid.selectedIndex >= 0)
{
myDataGrid.dataProvider.removeItemAt(myDataGrid.selectedIndex);
}
}

]]>
/fx:Script>
s:DataGrid requestedRowCount="4" id="myDataGrid"
width="500">
s:columns>
s:ArrayList>
s:GridColumn dataField="dataField1" headerText="列 1" id="col1">/s:GridColumn>
s:GridColumn dataField="dataField2" headerText="列 2">/s:GridColumn>
s:GridColumn dataField="dataField3" headerText="列 3">/s:GridColumn>
/s:ArrayList>
/s:columns>
s:typicalItem>
fx:Object dataField1="示例數(shù)據(jù)" dataField2="示例數(shù)據(jù)" dataField3="示例數(shù)據(jù)">/fx:Object>
/s:typicalItem>
s:ArrayList>
fx:Object dataField1="數(shù)據(jù)1" dataField2="數(shù)據(jù)1" dataField3="數(shù)據(jù)1">/fx:Object>
fx:Object dataField1="數(shù)據(jù)2" dataField2="數(shù)據(jù)2" dataField3="數(shù)據(jù)2">/fx:Object>
fx:Object dataField1="數(shù)據(jù)3" dataField2="數(shù)據(jù)3" dataField3="數(shù)據(jù)3">/fx:Object>
fx:Object dataField1="數(shù)據(jù)4" dataField2="數(shù)據(jù)4" dataField3="數(shù)據(jù)4">/fx:Object>
/s:ArrayList>
/s:DataGrid>

/s:Application>

標(biāo)簽:欽州 滄州 海西 呂梁 佛山 泰州 攀枝花 仙桃

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《在Flex中給datagrid添加右鍵菜單項(xiàng)的具體實(shí)現(xiàn)》,本文關(guān)鍵詞  在,Flex,中給,datagrid,添加,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《在Flex中給datagrid添加右鍵菜單項(xiàng)的具體實(shí)現(xiàn)》相關(guān)的同類信息!
  • 本頁收集關(guān)于在Flex中給datagrid添加右鍵菜單項(xiàng)的具體實(shí)現(xiàn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章