0
votes

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 ?

2
"2> Select checkboxes, and then delete the datagrid column" Do you mean "Delete datagrid row"?tefozi
Ya..delete row , not column. Sorry.user120118
Strange. It works for me. Sometimes the change event for the checkbox does not get processed until you click on another row of the datagridPhil C

2 Answers

3
votes

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>
0
votes

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