Add an item to the dataProvider
of the DataGrid from the change
event handler of the CheckBox - make sure you check for existing items (and remove them when check box is unchecked) to avoid duplicates. If you can post the code of DataGrid, we might be able to give a sample code showing how to do this.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="create()">
<mx:DataGrid id="dg" dataProvider="{dp}">
<mx:columns>
<mx:DataGridColumn dataField="console"/>
<mx:DataGridColumn dataField="price"/>
</mx:columns>
</mx:DataGrid>
<mx:CheckBox id="cb1" change="onCheck(event)"/>
<mx:CheckBox id="cb2" change="onCheck(event)"/>
<mx:CheckBox id="cb3" change="onCheck(event)"/>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var prices:Array = ["$20", "$30", "$15"];
private var labels:Array = ["PS1", "PS2", "PS3"];
private var checkBoxes:Array;
[Bindable]public var dp:ArrayCollection;
private function create():void
{
checkBoxes = [cb1, cb2, cb3];
for(var i:Number = 0; i < labels.length; i++)
CheckBox(checkBoxes[i]).label = labels[i];
dp = new ArrayCollection([]);
}
private function onCheck(event:Event):void
{
var cb:CheckBox = CheckBox(event.currentTarget);
var index:Number = indexOf(cb.label);
if(cb.selected && index == -1)
dp.addItem({console:cb.label,
price:prices[labels.indexOf(cb.label)]});
else if(!cb.selected && index != -1)
dp.removeItemAt(index);
}
private function indexOf(str:String):Number
{
for(var i:Number = 0; i < dp.length; i++)
{
var item:Object = dp.getItemAt(i);
if(item.console == str)
return i;
}
return -1;
}
]]>
</mx:Script>
</mx:Application>