5 Replies Latest reply on Aug 16, 2006 9:37 PM by doug777

    Remove focus in event listener

    doug777 Level 1
      myGrid.addEventListener(DataGridEvent.ITEM_EDIT_END, editHandler);

      At the end of editHandler, I would like to remove the focus on the cell in the DataGrid where the edit occurred.

      event.currentTarget.showFocusIndicator = false;

      doesn't work.

      Anyone know how to do this.

      And is the DataGrid's dataProvider automatically updated with the new value displayed in the cell even if I've modified it in editHandler, or do I somehow have to explicitly change the dataProvider and if so, how is this done?


        • 1. Re: Remove focus in event listener
          inlineblue Level 1
          It sounds like you've called preventDefault() on the itemEditEnd event, in which case you're on your own when it comes to processing an edit. To remove the editor, call grid.destroyItemEditor(). You'll also have to make your own changes back to the dataProvider using the info available in the event (rowIndex, dataField, etc.). Some more info here:


          It's easier to not cancel the default behaviour. Instead, make any changes you require to the cell editor's text. eg:

          var editor: TextInput = TextInput(itemEditorInstance);
          editor.text = "whatever";

          Once the event handler returns, the default behaviour will take the editor text and apply it to the dataprovider, and perform whatever cleanup is required.
          • 2. Re: Remove focus in event listener
            doug777 Level 1
            Thanks very much for the info, the edit all seems to work okay with itemEditorinstance, but I still have the problem that if the user hits the enter key to register the edit, the focus remains on the cell and this looks odd.

            How can I remove the focus, if the cell still has focus, at the end of the event handler?

            • 3. Re: Remove focus in event listener
              doug777 Level 1
              Does anyone know if I'm on the right track?

              I have set up a new Class called RemoveFocus:

              package accpages{

              import mx.managers.IFocusManagerComponent;

              public class RemoveFocus implements mx.managers.IFocusManagerComponent{

              public var draw:Boolean = true;
              private var tabi:uint;

              public function get focusEnabled():Boolean{return true}
              public function set focusEnabled(draw:Boolean):void{}
              public function get mouseFocusEnabled():Boolean{return true}
              public function get tabEnabled():Boolean{return true}
              public function get tabIndex():int{return tabi}
              public function setFocus():void{}
              public function drawFocus(draw:Boolean):void{}

              override public function drawFocus(draw:Boolean):void {}


              then import RemoveFocus and at the end of my event handler:

              var focus:RemoveFocus = new RemoveFocus();

              With this code I get an error on the override line: Duplicate function definition.

              If I remove the duplicate function (public function drawFocus ...) I get the error:
              Method marked override must override another method.


              Anyone know if this is going the right way, or what is wrong with my code??

              • 4. Re: Remove focus in event listener
                doug777 Level 1
                Oh got it ...

                You just don't need the override line at all.

                Without that everything seems to work and when you hit the enter key the data changes and the celll loses focus.

                Now I have to see if I have to explicitly return drawFocus to true after this.

                • 5. Re: Remove focus in event listener
                  doug777 Level 1
                  Pity, this is not the solution.

                  The above code removes the focus on the whole line in the DataGrid, but I only want to remove focus from the edited cell.

                  Anyone got any idea how to specify which component the FocusManager should be focused on?