Hi All,

Bought the Flash MX datagrid component from Macromedia. Standard it
does not handle the arrowkeys but they made an example on how to do it
using grid.setSelectedCell (code included on end of message).
Unfortunately setSelectedCel has the nasty habit of turning every cel
it targets into an editable cell even if it is not editable! The
function also sets the cel into edit mode adding typed characters to
the cell content instead of overwriting it.
Tab key navigation IS included in the datagrid and works just like it
should!
Any of you die-hard programmers know a solution ?


Here is my code:

All in frame1 with datagrid called "grid" on stage:

stop();
setData();
grid.setSelectable(false);
grid.setEditable(true);

// trap the arrow keys
this.tabListener = new Object();
Key.addListener(this.tabListener);

// key listener function
this.tabListener.onKeyDown = function() {
// get the coordinates
var myPos = grid.getSelectedCell();

// listen for the key and go in that direction
// each conditional calls the gridNav function
if (Key.isDown(Key.RIGHT)) {
gridNav(myPos.index, myPos.colName, "right");
} else if (Key.isDown(Key.LEFT)) { gridNav(myPos.index, myPos.colName,
"left");
} else if (Key.isDown(Key.UP)) { gridNav(myPos.index, myPos.colName, "up");
} else if (Key.isDown(Key.DOWN)) { gridNav(myPos.index, myPos.colName,
"down");
}
}

/*
this function checks the position of the current sellected
and stops if it has nowhere to go. You could also make it
wrap around to the next or previous row.

*/
function gridNav(index, col, dir) {
var colIndex = grid.getColumnIndex(col);

if (dir == "up") {
if (index == 0) {return;}
grid.setSelectedCell(index-1, col);
} else if (dir == "down") {
if (index == grid.getLength()-1) {return;}
grid.setSelectedCell(index+1, col)
} else if (dir == "right") {
if (colIndex == grid.getColumnCount()-1) {return;}
grid.setSelectedCell(index,
grid.getColumnAt(colIndex+1).getHeader())
} else if (dir == "left") {
if(colIndex == 0) {return;}
grid.setSelectedCell(index,
grid.getColumnAt(colIndex-1).getHeader())
}

trace("index: " + index);
trace("column: " + col);
trace("columnIndex: " + colIndex);
trace("direction: " + dir + "\n");
}



//-----------------
// get data locally
//-----------------
function setData()
{
var dP = new Array();
for (var i=0; i<10; i++) {
dP[i] = {first:"first", second:"second", nuts:"nuts",one:"one:"+i,
two:"two:"+i, three:"three:"+i, four:"four:"+i};
} grid.setDataProvider(dP);
}


----------------------------------------------------------------------------
----