I have a DataGrid that has a dataProvider bound to an ArrayCollection.
<code>
<mx:DataGrid id="dgEmployees"
dataProvider="{__employees}"
...>
</code>
I also have another DataGrid (dgAllEmployees) that is within a popup,
which I use as a source for Drag & Drop operations to populate the
dgEmployee dataGrid.
What I've noticed is that when I drag & drop employees from the "all
employees" DataGrid to the "employees" DataGrid, it seems to only
update the dataProvider of dgEmployees, and not the ArrayCollection
__employees. Why is this?
Below is a snip of my drag & drop code where it actually copies the
data. This is a generic method that is used all over the application.
<code>
public static function doDragDrop( event:DragEvent ):void
{
// Prevent the default event from happening.
event.preventDefault();
// Get drop target
var dropTarget:DataGrid = DataGrid(event.currentTarget);
// Get the dragged items from the drag initiator.
var dropItems:Array = event.dragSource.dataForFormat("items") as Array;
// Add each item to the drop target.
for (var i:uint = 0; i < dropItems.length; i++)
{
var dest:IList = IList(dropTarget.dataProvider);
if (!contains(dest, dropItems[i]))
{
dest.addItem(dropItems[i]);
}
}
}
</code>
I think that I had event.preventDefault(); in there because it was
putting 2 of each dropped item in the dgEmployee DataGrid. Might this
be messing something up?
Also, contains() is a custom method to compare the source items to
what's in the target's list to prevent duplicates. Is there a better
way to do this?
Thanks in advance.
GT