2
votes

I am trying to make an editable DataGrid to insert a new row when user presses TAB in the last column of last row.

My Grid:

  <mx:DataGrid id="myGrid"
      dataProvider="{initDG}" editable="true"
      itemFocusOut="onItemFocusOut(event)">
      <mx:columns>
          <mx:DataGridColumn dataField="Company" editable="false"/>
          <mx:DataGridColumn dataField="Contact"/>
      </mx:columns>
  </mx:DataGrid>

My onItemFocusOut event:

      protected function onItemFocusOut(e: DataGridEvent):void{
        if((e.rowIndex == (initDG.length - 1)) && 
           (e.columnIndex == (myGrid.columnCount -1))){
          initDG.addItem({Company: 'New one', Contact: ''});
        }
      }

It works fine, meaning it inserts a new row. The problem is that flex focuses on the next component and I need it to focus on the recently created row.

Is it possible?

Thnaks

1
Have you had a chance to try the answer I posted? If it helps solve your problem, you can upvote it by clicking on the ^ arrow and flag it as the accepted answer by clicking on the check mark icon next to my answer.Jason Towne

1 Answers

3
votes

I wouldn't do that if I were you. Tab is a very well known keyboard shortcut to go to the next cell or next row if at the last cell. Removing that functionality will impede on the standard functionality.

With that said, if you want to do it, you can either try to 'intercept' the keyboard event and do a 'stopImmediatePropogation()' on the event, or you can extend the DataGrid to add your own functionality for the Tab.