Warning: ob_start() [ref.outcontrol]: output handler 'ob_gzhandler' cannot be used twice in /home/vaishali/public_html/wp-includes/functions.php on line 408
Creativity Rules » Blog Archive » Set Focus on a Cell in Datagrid in Flex 2.0

Set Focus on a Cell in Datagrid in Flex 2.0

To set focus on a particular cell in Datagrid in Flex use the setFocusedCell(object,boolean) function. The object requires two properties itemIndex and columnIndex. Column index as the name signifies is the index or the column number of the column you want to select. Item index is the index or the row number of the row you want to select.

So your code would look something like this (dg is the instance name of the DataGrid):

The following method is for Flex 2 Beta 1:

var __focusedCell:Object = new Object();
__focusedCell.itemIndex = 1;
__focusedCell.columnIndex = 2;
dg.setFocusedCell(__focusedCell,true);

The following method is for Flex 2 Beta 2:

var __focusedCell:Object = new Object();
__focusedCell.rowIndex = 1;
__focusedCell.columnIndex = 2;
dg.setEditedItemPosition(__focusedCell);

So the above code would select the cell of 2nd row and the 3rd column. Remember indexes start from 0 and not 1 :)

One Response to “Set Focus on a Cell in Datagrid in Flex 2.0”

  1. FlexNinja Says:

    You can now use editedItemPosition with properties columnIndex and rowIndex.

Leave a Reply