我在datagrid中使用了iteamreander。如果我选择网格中的复选框,则自动选择另 复选框为何? plz解释我的xml数据超过50条记录。
<mx:DataGrid change="calculate()" id="calamount" x="0" y="3" width="327"
height="337" variableRowHeight="true"
dataProvider="{xml_coupon.lastResult.Teamcoupon.match_details}" >
<mx:columns>
<mx:DataGridColumn headerText="Away" dataField="away_team" width="100"/>
<mx:DataGridColumn headerText="1" rendererIsEditor="true"
editorDataField="selected">
<mx:itemRenderer>
<mx:Component>
<mx:HBox verticalAlign="middle" paddingLeft="2">
<mx:CheckBox id="checkbox1" selected="{outerDocument.checkedAll}"
click="{data.check1=checkbox1.selected;outerDocument.calcValues();}"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
答案 0 :(得分:4)
如果在滚动时发生这种情况,您可以将此代码用作ItemRender,它将解决您的问题:
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
implements="mx.controls.listClasses.IDropInListItemRenderer">
<mx:Script>
import mx.events.CollectionEvent;
import mx.collections.ArrayCollection;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.DataGrid;
import mx.controls.listClasses.BaseListData;
private var _listData:BaseListData;
private var _dataGrid:DataGrid;
[Bindable("dataChange")]
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListData):void {
_listData = value;
_dataGrid = value.owner as DataGrid;
}
override public function set data(value:Object):void {
super.data = value;
cb.selected = value["isSelected"];
}
private function onChange():void {
data["isSelected"] = cb.selected;
var dp:ArrayCollection = _dataGrid.dataProvider as ArrayCollection;
dp.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
}
</mx:Script>
<mx:CheckBox id="cb" horizontalCenter="0" change="onChange()" />
</mx:Canvas>