2 Replies Latest reply on Jan 24, 2012 5:21 AM by Mayur_2

    Can't focus on custom itemRenderer?

    jpwrunyan Level 1
      I have made a custom itemRenderer doubling as an itemEditor following the guidelines in the documentation.
      However, even though I have set the rendererIsEditor="true", when tabbing amongst other editable fields, the controls inside the itemRenderer do not receive focus. I can't help but think this is an oversight/bug but is there any way to jury-rig the itemRenderer to focus properly? At the moment my component is simply a CheckBox inside an HBox.

      Anyway, here is my code so you can see for yourself (I have included a CheckBox as itemRenderer so you can see the *desired* effect.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical">
      <mx:Script>
      <![CDATA[
      import mx.controls.dataGridClasses.DataGridListData;
      import mx.controls.Alert;
      [Bindable]
      public var dp:Array = [{num:2, bool:true}, {num:3, bool:false}];
      ]]>
      </mx:Script>
      <mx:DataGrid id="test" editable="true" dataProvider="{dp}">
      <mx:columns>

      <mx:DataGridColumn dataField="num" headerText="num" />
      <mx:DataGridColumn dataField="bool"
      headerText="Sent"
      itemRenderer="mx.controls.CheckBox"
      rendererIsEditor="true" editorDataField="selected" />

      <mx:DataGridColumn dataField="num" headerText="num" editable="true" />
      <mx:DataGridColumn dataField="bool" headerText="Sent" rendererIsEditor="true" editorDataField="blorch">
      <mx:itemRenderer>
      <mx:Component>
      <mx:HBox horizontalAlign="center">
      <mx:Boolean id="blorch" />
      <mx:CheckBox id="check" selected="{data.bool}" change="blorch=check.selected" />
      </mx:HBox>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      <mx:DataGridColumn dataField="num" headerText="num" editable="true" />
      </mx:columns>
      </mx:DataGrid>
      </mx:Application>
        • 1. Re: Can't focus on custom itemRenderer?
          jpwrunyan Level 1
          nevermind... I found the answer a few pages later in the docs...
          you have to implement the IFocusManagerComponent interface and then override drawFocus as below to set the focus on the checkBox... hope it works for multiple controls...


          <mx:HBox horizontalAlign="center" backgroundColor="#9933EE" implements="mx.managers.IFocusManagerComponent">
          <mx:Script>
          <![CDATA[
          override public function drawFocus(focused:Boolean):void {
          check.setFocus();
          }
          ]]>
          </mx:Script>
          <mx:Boolean id="blorch" />
          <mx:CheckBox id="check" selected="{data.bool}" change="blorch=check.selected" updateComplete="blorch=check.selected" />
          </mx:HBox>
          • 2. Re: Can't focus on custom itemRenderer?
            Mayur_2

            Good answer it works for Forward Tab.

            But when we user revers Tab order ( shift + Tab on win) it gives an error.