Feb 11

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 ;)