DataGrid 添加一行 自动获取焦点
id name
1 a
2 b
添加一个对象
id name
1 a
2 b
x x
然后 有没有办法 让焦点 直接 到
第一个 x 上面
[解决办法]
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" >
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var _mydata:ArrayCollection = new ArrayCollection();
private function init():void
{
var obj1:Object = new Object();
obj1.id=1; obj1.name="a";
var obj2:Object = new Object();
obj2.id=2; obj2.name="b";
this._mydata.addItem(obj1);
this._mydata.addItem(obj2);
}
private function handleAddItemToGrid():void
{
var obj3:Object = new Object();
obj3.id=3; obj3.name="c";
this._mydata.addItem(obj3);
this._mydata.refresh();
this.dg.selectedItem = obj3;
}
]]>
</mx:Script>
<mx:DataGrid x="10" y="10" id="dg" dataProvider="{this._mydata}">
<mx:columns>
<mx:DataGridColumn headerText="列 1" dataField="id"/>
<mx:DataGridColumn headerText="列 2" dataField="name"/>
</mx:columns>
</mx:DataGrid>
<mx:Button x="10" y="160" label="添加一项" id="button1" click="handleAddItemToGrid()"/>
</mx:WindowedApplication>