views:

2162

answers:

1

i used iteamreander in datagrid . if i select checkbox in grid automatically select another checkbox why? plz explain My xml data is more then 50 records.

<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>
+3  A: 

If this is happen when you scroll you can use this code as ItemRender and it will fix your problem :

<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>
ghalex
May i know what is reason checkbox was automatically select
R.Vijayakumar
For performance reasons, the DataGrid will cache checkboxes and reuse them for different rows. If you have 50 rows, it won't create 50 checkboxes. It will create as many checkboxes at are visible, plus a few more for padding, and then reuse them as you scroll. This is why you need to explicitly manage their state.
Mike Sickler
Thanks for comments .. How can i solve it and manage the state ? Could u tell me clearly ?
R.Vijayakumar