У меня были те же проблемы с вкладками одного из itemRenderer в моем AdvancedDataGrid (кстати, я использую Flex SDK 3.5), но этот пост был чрезвычайно полезен, так как позволил мне сделать мой ItemRenderer удобным для вкладок, чтобы я мог хотел бы также внести свой вклад:)
Чтобы это работало, вам также нужно изменить несколько свойств в grid и gridColumn.
Давайте сначала поговорим о grid и gridColumn.
Как вы все знаете, когда вы устанавливаете свойство "editable" сетки в значение "true", вы можете перемещаться по каждой ячейке столбца (при условии, что вы не установили свойство "editable" столбца в значение "false").
Шаг # 1 , установите для свойства "editable" вашей сетки значение "true"
Шаг # 2 , установите для свойства "editable" столбца вашей сетки значение, равное "true", а для rendererIsEditor - "true"
Важно установить для dataField фиктивное поле, потому что, поскольку мы устанавливаем средство визуализации в качестве редактора, это означает, что все, что вы обновляете в itemRenderer, будет назначено на dataField, т.е. вы устанавливаете dataField в «Foo», который имеет тип int и у вас есть не примитивные объекты, заполняющие ComboBox itemRenderer. Когда вы сделаете выбор, этот объект будет присвоен "Foo"
Шаг № 3 , сделайте так, чтобы свойство столбца вашей сетки dataField также устанавливало поддельное поле.
Теперь давайте сделаем так, чтобы вкладки работали на itemRenderer
Я знаю, что это не оптимизированная версия, но она подойдет для 1-го прохода.
import mx.core.mx_internal;
import mx.managers.IFocusManagerComponent;
use namespace mx_internal;
public class FriendlyItemRendererContainer extends HBox implements IFocusManagerComponent
{
public function FriendlyItemRendererContainer ()
{
super();
addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler);
}
private var _listData:DataGridListData;
//This is required to make it work as itemEditor
public var text:String;
private function keyFocusChangeHandler(event:FocusEvent):void
{
if (event.keyCode == Keyboard.TAB &&
! event.isDefaultPrevented() &&
findNextChildToFocus(event.shiftKey))
{
event.preventDefault();
}
}
private function findNextChildToFocus(shiftKey:Boolean):Boolean
{
var myChildrenAry:Array = getChildren();
var incr:int = shiftKey ? -1 : 1;
var index:int = shiftKey ? myChildrenAry.length : 0;
var focusChildIndex:int = 0;
var found:Boolean = false;
for (focusChildIndex = 0; focusChildIndex < myChildrenAry.length; ++focusChildIndex)
{
if (!(myChildrenAry[focusChildIndex] as UIComponent).visible ||
(myChildrenAry[focusChildIndex] is Container))
{
//If it's an invisible UIComponent or a container then just continue
continue;
}
if (myChildrenAry[focusChildIndex] is TextInput)
{
if (systemManager.stage.focus == (myChildrenAry[focusChildIndex] as TextInput).getTextField())
{
(myChildrenAry[focusChildIndex] as UIComponent).drawFocus(false);
found = true;
break;
}
}
else
{
if (systemManager.stage.focus == myChildrenAry[focusChildIndex])
{
(myChildrenAry[focusChildIndex] as UIComponent).drawFocus(false);
found = true;
break;
}
}
}
if (!found)
{
focusChildIndex = 0;
}
while (true)
{
focusChildIndex = focusChildIndex + incr;
if ((focusChildIndex < 0) || (focusChildIndex >= myChildrenAry.length))
{
UIComponentGlobals.nextFocusObject = null;
return false;
}
else
if (myChildrenAry[focusChildIndex] is UIComponent)
{
(myChildrenAry[focusChildIndex] as UIComponent).setFocus();
(myChildrenAry[focusChildIndex] as UIComponent).drawFocus(true);
break;
}
}
return true;
}
override public function setFocus():void
{
var myChildrenAry:Array = getChildren();
if (myChildrenAry.length > 0)
{
for (var i:int = 0; i < myChildrenAry.length; ++i)
{
if ((myChildrenAry[i] is UIComponent) && (myChildrenAry[i] as UIComponent).visible)
{
(myChildrenAry[i] as UIComponent).setFocus();
(myChildrenAry[i] as UIComponent).drawFocus(true);
break;
}
}
}
}
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListData):void
{
_listData = DataGridListData(value);
}
}
Пример использования его на вашем itemRenderer:
<FriendlyItemRendererContainer xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:TextInput/>
<mx:Button label="Boo"/>
<mx:RadioButton/>
<<mx:TextInput/>
<mx:Button label="Baa"/>
</FriendlyItemRendererContainer>
Затем просто поместите это в gridColumn и все.
Наслаждайтесь.