flex dataGrid 光标定位问题
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="700" verticalScrollPolicy="on">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.*;
import mx.events.AdvancedDataGridEvent;
import mx.collections.ArrayCollection;
import mx.controls.dataGridClasses.DataGridColumn;
[Bindable]
private var dataSource:ArrayCollection = new ArrayCollection([
{},{},{},{},{},{},
]);
internal function removeRow():void{
dataSource.removeItemAt(dataSource.length-1);
}
internal function addRow():void{
dataSource.addItemAt({},dataSource.length-1);
}
private function labelFunc(item:Object,column:AdvancedDataGridColumn):String
{
return (this.dg1.dataProvider.getItemIndex(item)+1).toString();
}
]]>
</mx:Script>
<mx:Canvas verticalScrollBarStyleName="hh" height="614" width="831.5" horizontalCenter="-1" verticalCenter="0" verticalScrollPolicy="auto">
<mx:Button x="514" y="559" click="removeRow()" label="删除所选行" fontSize="12"/>
<mx:Button click="addRow()" label="添加一行" x="200" y="559" fontSize="12"/>
<mx:AdvancedDataGrid id="dg1" designViewDataType="flat" sortExpertMode="true" sortableColumns="false" rowCount="5"
dataProvider="{dataSource}" height="441" width="811.5" fontSize="14" fontFamily="Times New Roman" editable="true"
enabled="true" x="10" y="55" >
<mx:groupedColumns>
<mx:AdvancedDataGridColumn headerText="序号" dataField="xh" width="150" editable="false" textAlign="center" labelFunction="labelFunc"/>
<mx:AdvancedDataGridColumn headerText="COL1" dataField="col1" width="200" textAlign="center" />
<mx:AdvancedDataGridColumn headerText="COL2" dataField="col2" width="200" textAlign="center" />
<mx:AdvancedDataGridColumn headerText="COL3" dataField="col3" width="250" textAlign="center" />
<mx:AdvancedDataGridColumn headerText="COL4" dataField="col4" width="200" textAlign="center"/>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
</mx:Canvas>
</mx:Application>
实例代码如上,想实现的效果是,当单击添加一行按钮时,dataGrid添加一行并且光标定位在所添加行的可编辑单元格(即新加行的COL2列上),谢谢高手指点!
[解决办法]
dataGrid.editedItemPosition={columnIndex:columnindex,rowIndex:rowindex};