Checkbox itemrenderer in datagrid

The selected property of the checkbox has to be bounded with the selected property of our entity,  Itemrenderer doesn’t keep track of the selected states correctly this can be fixed by binding data with selected property.Freelance Flash Flex developer India Bangalore

The below code explains the itemrender file called DGCheckBoxEditor

<mx:Script>
<![CDATA[
import mx.controls.listClasses.ListData;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.controls.dataGridClasses.DataGridItemRenderer
import mx.events.FlexEvent;

private var _listData:DataGridListData;
// Define a property for returning the new value to the cell.
public var cbSelected:Boolean;

// Implement the drawFocus() method for the VBox.
override public function drawFocus(draw:Boolean):void {
followUpCB.setFocus();
}

[Bindable]
override public function set data(value:Object):void{
super.data = value;
followUpCB.selected=data[_listData.dataField];
}

override public function get data():Object {
return super.data;
}

public function get listData():BaseListData
{
return _listData;
}

public function set listData(value:BaseListData):void
{
_listData = DataGridListData(value);
}

]]>
</mx:Script>

<mx:CheckBox id=”followUpCB”
change=”cbSelected=followUpCB.selected” paddingLeft=”15″/>

Code to call the itemrender

<mx:DataGrid id=”myGrid”
dataProvider=”{myAC}” editable=”true” >
<mx:columns>
<mx:DataGridColumn id=”checker” dataField=”FollowUp”
width=”50″
headerText=”Select”
itemRenderer=”DGCheckBoxEditor” rendererIsEditor=”true”
editorDataField=”cbSelected”/>
<mx:DataGridColumn id=”checker1″ dataField=”Contact” width=”150″ />
<mx:DataGridColumn dataField=”id” width=”150″ editable=”false”/>
</mx:columns>
</mx:DataGrid>

Leave a comment