User Guide

DataGrid.cellEdit 273
When the event is triggered, it automatically passes an event object (eventObject) to the
handler. Each event object has properties that contain information about the event. You can
use these properties to write code that handles the event. The
DataGrid.cellEdit events
event object has four additional properties:
columnIndex A number that indicates the index of the target column.
itemIndex A number that indicates the index of the target row.
oldValue The previous value of the cell.
type The string "cellEdit".
For more information, see “EventDispatcher class” on page 499.
Example
In the following example, a handler called myDataGridListener is defined and passed to
myDataGrid.addEventListener() as the second parameter. The event object is captured by
the
cellEdit handler in the eventObject parameter. When the cellEdit event is broadcast
(after you alter a “score” value and press Enter), a
trace statement is sent to the Output panel.
With a DataGrid instance named
my_dg on the Stage, paste the following code in the first
frame of the main timeline:
my_dg.setSize(320, 240);
my_dg.editable = true;
// Add columns and make the first one not editable.
my_dg.addColumn("name");
my_dg.getColumnAt(0).editable = false;
my_dg.addColumn("score");
var myDP_array:Array = new Array();
myDP_array.push({name:"Clark", score:3135});
myDP_array.push({name:"Bruce", score:403});
myDP_array.push({name:"Peter", score:25});
// Set data source of DataGrid.
my_dg.dataProvider = myDP_array;
// Create listener object.
var myListener_obj:Object = new Object();
myListener_obj.cellEdit = function(evt_obj:Object) {
// Retrieve location of cell that was changed.
var cell_obj:Object = "("+evt_obj.columnIndex+", "+evt_obj.itemIndex+")";
// Retrieve cell value that was changed.
var value_obj:Object = evt_obj.target.selectedItem.score;
trace("The value of the cell at "+cell_obj+" has changed to "+value_obj);
};
// Add listener object.
my_dg.addEventListener("cellEdit", myListener_obj);