I have a grid table that contains ship objects(data provider accepts a array collection of ships objects) and displays just the name of ship and date in the grid table. My ship object has a property called checkList a boolean value, To be used as data binding in my checkbox item renderer.(To make the check box ,tick and untick)
I want to check my checkbox when I add a Image object in to a container. The Image object that is being added to the container has a id. I want to match that Image id to my shipId in the data grid table and check the check box for that particular record.
So my Image object listens to the add event and so when the Image object is added to a container. It calls the addHandler() function where it gets the id of the image and the loops though the data grid table to find the matching id and check the CheckBox. My looping works nicely.Using Alert.show() I can see that it matches the id and sets the boolean value to, true for the check box to be ticked. However the check box is not ticked.
These are my codes. Even though the checkList property for that particular record is set to true. The check box is not ticked. I dont Know whats the problem is. I am a student and new to flex.Can some one pls help me ?
My MXML view: My Grid Table
<s:DataGrid id="arrivalTable" x="-1" y="-1" width="302" height="205" requestedRowCount="4"
dataProvider="{myArrivalShips}" >
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="shipName" headerText="Arrival Ships" itemRenderer="DesignItemRenderer.myCustomToolTipRenderer" width="130" ></s:GridColumn>
<s:GridColumn dataField="ETA" headerText="ETD" itemRenderer="DesignItemRenderer.myCheckBoxRenderer"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
My Image object listens add event.
displayImg.addEventListener(FlexEvent.ADD,addHandler);
This is my addHandler() event Function:
protected function addHandler(event:FlexEvent):void
{
var ImageShipId:String = Image(event.currentTarget).id;
var destination:BorderContainer = Image(event.currentTarget).owner as BorderContainer;
var destinationId:String = destination.id;
if( destinationId == "bct_HoldingArea" ){
for(var j:int = 0; j<arrivalTable.dataProvider.length; j++){
var myShip:Ship = arrivalTable.dataProvider.getItemAt(j) as Ship;
var myShipId:String = myShip.shipID.toString();
if(StringUtil.trim(myShipId) == StringUtil.trim(ImageShipId)){
myShip.checkList = true;
Alert.show("The ship name : " + myShip.shipName +"\n" + "The Ship selected : " + myShip.checkList);
}
}
}
}
My check Box Item renderer :
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
<s:HGroup>
<s:Label text="{data.ETD}" paddingTop="8"/>
<s:CheckBox id="myCheckBox" enabled="false" selected="{data.checkList}" />
</s:HGroup>