Just added a clone function to the simpleclass. The rest should be fine for you.
//MXML
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:ns1="*" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.SortField;
import mx.collections.Sort;
import mx.collections.ArrayCollection;
[Bindable]
private var ac:ArrayCollection = new ArrayCollection([
new SimpleClass("a",3,6),
new SimpleClass("a",3,6),
new SimpleClass("a",3,6),
new SimpleClass("a",3,6),
new SimpleClass("a",3,6),
new SimpleClass("b",5,8),
new SimpleClass("b",5,8),
new SimpleClass("b",5,8),
new SimpleClass("c",1,9),
new SimpleClass("c",1,9),
new SimpleClass("c",1,9),
new SimpleClass("d",2,5),
new SimpleClass("d",2,5),
]);
[Bindable]
private var acg:ArrayCollection = new ArrayCollection();
private function init(){
var cm:ContextMenu = new ContextMenu();
cm.hideBuiltInItems();
var item:ContextMenuItem = new ContextMenuItem("Create Copy");
cm.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onSelectItem);
dg.contextMenu = cm;
}
private function onSelectItem(e:ContextMenuEvent):void{
if(dg.selectedIndex >= 0){
var copyItem:SimpleClass = SimpleClass(dg.selectedItem).clone();
copyItem.title = "Copy -" + copyItem.title;
ac.addItem(copyItem);
}else{
Alert.show("Select an item to copy","ATTENTION");
}
}
]]>
</mx:Script>
<!-- THIS IS THE EDITABLE DG -->
<mx:DataGrid id="dg" dataProvider="{ac}" editable="true">
<mx:columns>
<mx:DataGridColumn dataField="title" editable="false" />
<mx:DataGridColumn dataField="value1" editorDataField="value" >
<mx:itemEditor>
<mx:Component>
<mx:NumericStepper minimum="2" maximum="25" />
</mx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="value2" editorDataField="value">
<mx:itemEditor>
<mx:Component>
<mx:NumericStepper minimum="2" maximum="25" />
</mx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Application>
//SimpleClass.as
package
{
public class SimpleClass
{
[Bindable]
private var _title:String = "";
[Bindable]
private var _v1:int = 0;
[Bindable]
private var _v2:int = 0;
public function SimpleClass(tit:String = "", v1:int = 0,v2:int = 0){
value1 = v1;
value2 = v2;
title = tit;
}
[Bindable]
public function get value1():int{
return _v1;
}
public function set value1(v:int):void{
_v1 = v;
}
[Bindable]
public function get value2():int{
return _v2;
}
public function set value2(v:int):void{
_v2 = v;
}
[Bindable]
public function get title():String{
return _title;
}
public function set title(v:String):void{
_title = v;
}
public function clone():SimpleClass{
return new SimpleClass(title,value1,value2);
}
}
}
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126:





by: PluckaPosted on 2008-04-01 at 22:10:35ID: 21260318
Firstly Flash and thus Flex only allows limited access to right click. You can customise the Right Click context menu, but it will still have the Flash options that you see when you right click now, and there is no way to get rid of that.
It's a real pain, I wish they would just let you use right click if you wanted to.
So you may want to think of a different method, ie selecting the row then selecting an option from a menu somewhere.