views:

524

answers:

1

I'm having difficulty getting checkboxes on only the leaf nodes of a tree.

Before anyone links it, I've seen http://www.sephiroth.it/file_detail.php?id=151# and this isn't exactly what I need. I don't want a 3-state checkbox system including both branch and leaf.

I understand applying the checkbox item renderer to a data grid but not on a tree.

I'm using Flex Builder 3

A: 

Let's say that we want to put the Checkbox in one of the columns of AdvancedDataGrid. I like using HierarchicalData or HierarchicalCollectionView as my datagrid's dataProvider:

// TestGrid
<mx:AdvancedDataGrid id="myADG">
    <mx:columns>
        <AdvancedDataGridColumn id="col1" />
        <AdvancedDataGridColumn id="col2" itemRenderer="LeafCheckbox" />
    </mx:columns>
</mx:AdvancedDataGrid>



// LeafCheckBox.mxml
<mx:Box 
    creationComplete="init(event)"
    implements="IDropInListItemRenderer">
<mx:Script>
    <![CDATA[

    // Internal variable for the property value.
    private var _listData:BaseListData;

    // Make the listData property bindable.
    [Bindable("dataChange")]

    // Define the getter method.
    public function get listData():BaseListData
    {
      return _listData;
    }

    // Define the setter method,
    public function set listData(value:BaseListData):void
    {
      _listData = value;
    }


    private function init(event:Event):void {
        var dg:AdvancedDataGrid = this.listData.owner.parent as AdvancedDataGrid;
        if (!dg.dataProvider.hasChildren(dg.selectedItem))
            this.addChild(new CheckBox());
    }

    ]]>
</mx:Script>

</mx:Box>

That should be most of it. Let me know, thanks!

Luis B