Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Add an item to the <code>dataProvider</code> of the DataGrid from the <code>change</code> 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.</p> <pre><code>&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="create()"&gt; &lt;mx:DataGrid id="dg" dataProvider="{dp}"&gt; &lt;mx:columns&gt; &lt;mx:DataGridColumn dataField="console"/&gt; &lt;mx:DataGridColumn dataField="price"/&gt; &lt;/mx:columns&gt; &lt;/mx:DataGrid&gt; &lt;mx:CheckBox id="cb1" change="onCheck(event)"/&gt; &lt;mx:CheckBox id="cb2" change="onCheck(event)"/&gt; &lt;mx:CheckBox id="cb3" change="onCheck(event)"/&gt; &lt;mx:Script&gt; &lt;![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 &lt; 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 &amp;&amp; index == -1) dp.addItem({console:cb.label, price:prices[labels.indexOf(cb.label)]}); else if(!cb.selected &amp;&amp; index != -1) dp.removeItemAt(index); } private function indexOf(str:String):Number { for(var i:Number = 0; i &lt; dp.length; i++) { var item:Object = dp.getItemAt(i); if(item.console == str) return i; } return -1; } ]]&gt; &lt;/mx:Script&gt; &lt;/mx:Application&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload