У меня проблемы с получением фокуса для работы с моей собственной сеткой данных. Это подкласс MDataGrid, который можно найти здесь .
Моя проблема в том, что каждый второй щелчок мышью на встроенных компонентах фактически фокусируется на компоненте. Другие щелчки, кажется, автоматически теряют фокус на что-то еще, и я не могу понять, что происходит. Любая помощь будет принята с благодарностью.
Спасибо за ваше время.
- Charly
<?xml version="1.0" encoding="utf-8"?>
<controls:MDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="com.iwobanas.controls.*"
xmlns:dgc="com.iwobanas.controls.dataGridClasses.*"
dataProvider="{locator.vendorInvoices}"
editable="true">
<mx:Script>
<![CDATA[
import model.PayablesLocator;
[Bindable] private var locator:PayablesLocator = PayablesLocator.getInstance();
]]>
</mx:Script>
<controls:columns>
<dgc:MDataGridColumn dataField="loadNumber"
headerText="Load"
editable="false"/>
<dgc:MDataGridColumn dataField="carrierName"
headerText="Carrier"
editable="false"/>
<mx:DataGridColumn headerText="Vendor Invoice #"
rendererIsEditor="true"
editorDataField="vendorInvoiceNumber">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.controls.listClasses.IDropInListItemRenderer, mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.events.FlexEvent;
private var _listData:DataGridListData;
[Bindable] public var vendorInvoiceNumber:String;
// Implements mx.managers.IFocusManagerComponent
override public function drawFocus(draw:Boolean):void {
invoiceNumberInput.setFocus();
}
// Implements mx.controls.listClasses.IDropInListItemRenderer
override public function get data():Object {
return super.data;
}
override public function set data(value:Object):void {
super.data = value;
invoiceNumberInput.text = data.vendorInvoiceNumber
}
public function get listData():BaseListData {
return _listData;
}
public function set listData(value:BaseListData):void {
_listData = DataGridListData(value);
}
private function onChange(event:Event):void {
data.vendorInvoiceNumber = invoiceNumberInput.text;
}
]]>
</mx:Script>
<mx:TextInput id="invoiceNumberInput"
width="95%"
change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Vendor Invoice Date"
rendererIsEditor="true"
editorDataField="vendorInvoiceDate">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import mx.events.CalendarLayoutChangeEvent;
[Bindable] public var vendorInvoiceDate:Date;
// Implements mx.managers.IFocusManagerComponent
override public function drawFocus(draw:Boolean):void {
vendorInvoiceDateInput.setFocus();
}
protected function onChange(event:CalendarLayoutChangeEvent):void {
data.vendorInvoiceDate = event.newDate;
}
]]>
</mx:Script>
<mx:DateField id="vendorInvoiceDateInput"
width="95%"
editable="true"
change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn editorDataField="isSelected"
headerText="Select"
rendererIsEditor="true">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.controls.listClasses.IDropInListItemRenderer,mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import controller.PayablesController;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
private var control:PayablesController = PayablesController.getInstance();
private var _listData:DataGridListData;
[Bindable] public var isSelected:Boolean;
override public function drawFocus(draw:Boolean):void {
selectionCheckBox.setFocus();
}
override public function get data():Object {
return super.data;
}
override public function set data(value:Object):void {
super.data = value;
selectionCheckBox.selected = data.isSelected
}
public function get listData():BaseListData {
return _listData;
}
public function set listData(value:BaseListData):void {
_listData = DataGridListData(value);
}
protected function onChange(event:Event):void {
data.isSelected = selectionCheckBox.selected;
control.updateBatchSelections();
}
]]>
</mx:Script>
<mx:CheckBox id="selectionCheckBox" change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</controls:columns>