vendredi 13 janvier 2017

Restrict drag and drop of some items in a datagrid? - Adobe Flex

I want to limit the drag and drop of a particular item in a datagrid. Not all items will be added in the datagrid. For example, when I click and drag an item X to the datagrid, it is added. And if I click and drag another item, Y, to the same datagrid, it will not be added.

<s:Label text="Source"/>
<mx:DataGrid id="srcgrid"
    allowMultipleSelection="true" 
    dragEnabled="true" 
    dropEnabled="true" 
    dragDrop="dragDropHandlerSrc(event);"
            dragMoveEnabled="true">
            <mx:columns>
                <mx:DataGridColumn dataField="Expense"/>
                <mx:DataGridColumn dataField="Value"/>
            </mx:columns>    
        </mx:DataGrid>

<s:Label text="Costs"/>
<mx:DataGrid id="costgrid"
    allowMultipleSelection="true" 
    dragEnabled="true" 
    dropEnabled="true" 
    dragMoveEnabled="true"
    dragDrop="dragDropHandlerCost(event);">
    <mx:columns>
        <mx:DataGridColumn dataField="Espense"/>
        <mx:DataGridColumn dataField="Value"/>
    </mx:columns>    
</mx:DataGrid>

<fx:Script>
    private function initApp():void {
        srcgrid.dataProvider = new ArrayCollection([
        {Expense:'Electricity', Value:100},
        {Expense:'Phone', Value:200},
        {Expense:'Water', Value:300},
        {Expense:'Contract A', Value:500},
        {Expense:'Contract B', Value:600}
        ]);

        costgrid.dataProvider = new ArrayCollection([]);
    }
</fx:Script>

In this example, the items Electricity, Phone and Water from srcgrid will be added in datagrid costgrid. And the item Contract A will be not added in costgrid.

Any idea?

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire