views:

3960

answers:

4

Hi, I am trying to implement the following :

1> First column of datagrid has a checkbox. 2> Select checkboxes, and then delete the datagrid column. 3> Dynamically, add checkbox when row is added dynamically. 4> Do not show check box if now data in row.

Can someone give some guidance ?

+1  A: 

I am assuming you want to delete a row and not a column. The following works

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
       layout="vertical">
    <mx:Script>
     <![CDATA[
      import mx.events.IndexChangedEvent;
      import mx.collections.ArrayCollection;
      import mx.controls.Alert;

      [Bindable]
      private var ac:ArrayCollection=new ArrayCollection([{name: "John", shouldDelete: true}, {name: "Joe", shouldDelete: false}, {name: "Jill", shouldDelete: false}])


      private function deleteRows()
      {
       for each (var row:Object in ac)
       {
        if (row.shouldDelete == true)
        {
         var i:int=ac.getItemIndex(row);
         ac.removeItemAt(i);
        }
       }
      }
     ]]>
    </mx:Script>

    <mx:VBox>
     <mx:DataGrid id="dg"
         dataProvider="{ac}">
      <mx:columns>
       <mx:DataGridColumn dataField="name">

       </mx:DataGridColumn>
       <mx:DataGridColumn id="col2"
              editorDataField="selected"
              rendererIsEditor="true"
              dataField="data.shouldDelete">
        <mx:itemRenderer>
         <mx:Component>
          <mx:CheckBox label="Test"
              selected="{data.shouldDelete}"
              change="data.shouldDelete=selected"/>
         </mx:Component>
        </mx:itemRenderer>
       </mx:DataGridColumn>

      </mx:columns>

     </mx:DataGrid>
     <mx:Button label="delete"
          id="deleteBtn"
          click="deleteRows()"/>

    </mx:VBox>
</mx:Application>
Phil C
The delete is not deleting the row. Nothing happensa apart from checkbox getting selected. Any idea ?
A: 

Strange. It works for me. Sometimes the change event for the checkbox does not get processed until you click on another row of the datagrid

Phil C
A: 

In itemdatabound u should give enabled as false in particular cell....

Domnic
A: 

it works fine ...,though i had different functionality,I had to pick the selected record and iterate over the record to perform operations.

Jyoti