Programatically select a DataGrid cell in Flex

Recently I was trying to improve the usability of a Flex DataGrid for data entry purposes. What I wanted was that when I insert a new row into the grid, it would automatically give keyboard focus to the first cell in the new row.

I found that the editedItemPosition property allows you to specify the cell to edit by row and column indexes. However I found that modifying like so doesn’t do anything:

The reason that it doesn’t work is quite simply because the datagrid isn’t watching for changes to the rowIndex or columnIndex properties inside the editedItemPosition object. Also the editedItemPosition object isnt informing the DataGrid it has been modified. Instead, it is watching for changes to its own editedItemPosition property. In other words, you have to modify the editedItemPosition property for it to work. Here’s a example of the final result:

If you have any questions, fire them in the comments and I’ll get back to you asap ;)

6 thoughts on “Programatically select a DataGrid cell in Flex

  1. I have a similar problem. I am calculating the value of a non selectable column (Column 2) then going to the next value to edit (Column 3,4, or 5). The
    dataGrid.editedItemPosition = {rowIndex: theRow, columnIndex: theCol};
    Selects and opens the right cell so it looks like you can edit it but the keyboard entry is not recognized til the user clicks in the cell?

Leave a Reply