OK, First thing to do, read about flash.ui.ContextMenu Class.
Some points..
->In SWF content, any object that inherits from InteractiveObject can be given a context menu by assigning a menu object to its contextMenu property.
->In Flex, only top-level components in the application can have context menus.
->Flash Player has three types of context menus:standard menu ,the edit menu and an error menu.Only the standard and edit menus can be modified with the ContextMenu class.
…
so first create a ContextMenu for the DataGrid like below..
private function fnDgContextMenu():ContextMenu
{
var newContextMenu:ContextMenu = new ContextMenu();
var newContextMenuItem:ContextMenuItem=new ContextMenuItem(“Sort”);
newContextMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,fnSortSelect);
newContextMenu.customItems.push(newContextMenuItem);
return newContextMenu;
}
now assign it to DataGrid.
dg.contextMenu=fnDgContextMenu(); // here dg is the “id” of the DataGrid.check the code below.
Enjoy the post.
Posted by kumargandhi 