Thanks Tracy. That helped. Now I am able to enable item editor for the first
cell of a new row in the grid when the "add new" button is clicked.
However I ran into another issue. I am also trying to add a new row to the
Grid and enable item editor for the first cell of the new row, if the user tabs
out of the last cell of the previous row. I am calling the editedItemPosition()
in DataGridEventReason.NEW_ROW and also DataGridEventReason.OTHER in the
itemEditEnd handler for the Grid, but it is not working. When I tab out of the
last filled row of the Grid, focus is going out of the Grid and to the address
bar of the browser and when I tab again it comes to the last cell of the last
row and then the next tab is taking me to the first cell of the new row and
then item editor gets activated this time. Not sure what I am missing.
Appreciate if you can let me know what I am missing here.
Attached the code.
private var bLastCellOut:Boolean = false;
//if the user tabbed out of the last cell of the last row
//then add a new row and activate the itemEditor for the first cell
//in the next row...
private function editEnd(event

ataGridEvent):void
{
var item:BacklogItem = backlogsAr[event.rowIndex];
var errMsg:String = "";
var value:String = TextInput(event.currentTarget.itemEditorInstance). text;
TextInput(event.currentTarget.itemEditorInstance). errorString = errMsg;
//User trying to enter to a new column in the same row
//Validate the data in the current column and prevent it if the validation
fails...
if(event.reason == DataGridEventReason.NEW_COLUMN)
{
bLastCellOut = false;
errMsg = item.ValidateDataInput(event.dataField, value);
if(errMsg != "")
{
event.preventDefault();
TextInput(event.currentTarget.itemEditorInstance). errorString =
errMsg;
}
}
else
{
//User trying to enter to a new row
//Validate the data in the current column and prevent it if the validation
fails...
//If the validation is successful, create the new empty row in the Grid
if(event.reason == DataGridEventReason.NEW_ROW)
{
errMsg = item.ValidateDataInput(event.dataField, value);
if(event.rowIndex == (backlogsAr.length - 1))
{
if(errMsg != "")
{
event.preventDefault();
TextInput(event.currentTarget.itemEditorInstance). errorString =
errMsg;
}
else
{
bLastCellOut = true;
//Alert.show("Adding the new Row...");
addNewRow();
}
}
}
else
{
//User is trying focus out of this control, remove the empty rows if
exists...
if(event.reason == DataGridEventReason.OTHER)
{
//Alert.show("Leaving the control...");
if(bLastCellOut == true)
{
bLastCellOut = false;
bklogsGrid.setFocus();
event.preventDefault();
setEditPosition();
}
//addNewRow();
}
}
}
}
private function addNewRow():void
{
var obj:BacklogItem = new BacklogItem();
backlogsAr.addItemAt(obj, backlogsAr.length);
setEditPosition();
}
}
private function setEditPosition():void
{
if(backlogsAr.length > 0)
{
var newRowPos:Object = new Object();
newRowPos.columnIndex = 0;
newRowPos.rowIndex = backlogsAr.length-1;
bklogsGrid.editedItemPosition = newRowPos;
}
}