[flexcoders] Re: Does Drag Drop Only Update the DataProvider?
collectionChange doesn't appear to be a valid DataGrid event, but I tried dataChanged, added, add, valueCommit, and updateComplete. None of these did what I wanted, and actually, I have verified that the __employees ArrayCollection does not update after a DD event. Looking through everything in debug mode, I'm seeing that the dataProvider of the DataGrid is updated after DD, but not the bound variable __employees. I wonder if it's how I declared the variable? I did it like so: code [Bindable] private var __employees:ArrayCollection; public function get employees():ArrayCollection { return __employees; } public function set employees( employees:ArrayCollection ):void { if (employees != null) { __employees = employees; } } /code Maybe I should just make it public? Nope, that didn't work. I'm also wondering if the event.preventDefault(); is messing something up. Nope, that just prevents the the base class ListBase from doing it's DD handling. Since this doesn't check for duplicates, I don't want to use it. I'm not sure what to do --- In flexcoders@yahoogroups.com, Alex Harui [EMAIL PROTECTED] wrote: Mx:DataGrid's change event is for when selection changes, not when the collection changes. Could that be the issue? collectionChange may be what you want. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Sent: Friday, May 18, 2007 10:12 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? I don't have the code in front of me right now, but to be more precise, dgEmployees is not broadcasting a change event upon a DD action. I want dgEmployees to broadcast an event every time there is a change to the DataGrid. The dgEmployees DataGrid has a change event method defined, somthing like: code mx:DataGrid id=dgEmployees dataProvider={__employees} change=broadcastEvent(event) ... /code The broadcastEvent() method constructs a custom event containing the number of elements in the DataGrid, and then dispatches it to be used elsewhere. Now, as I type this, I see that I might have keyed off the wrong event, change. Not sure if that is broadcast upon a change in the dataProvider, BUT I had been working on this code previously (converting to Flex 2.0), and I believe that I saw this same issue. I noticed that when I used the debugger to step throught the doDragDrop() method, I was seeing that only the dataProvider was being updated, and not the ArrayCollection. I can't verify this until Monday (5/21), but I'm almost 100% sure this is what I saw. --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui aharui@ wrote: How do you know it didn't update __employees? Can you post a mini-example in a couple of screenfuls of text? From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Thursday, May 17, 2007 6:11 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Does Drag Drop Only Update the DataProvider? 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
RE: [flexcoders] Re: Does Drag Drop Only Update the DataProvider?
collectionChange is dispatched from the collection and not the DataGrid. Binding to private variables is not recommended, but not the problem either. Can you fit an entire example in two screens of text? If so, post it. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Sent: Monday, May 21, 2007 9:56 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? collectionChange doesn't appear to be a valid DataGrid event, but I tried dataChanged, added, add, valueCommit, and updateComplete. None of these did what I wanted, and actually, I have verified that the __employees ArrayCollection does not update after a DD event. Looking through everything in debug mode, I'm seeing that the dataProvider of the DataGrid is updated after DD, but not the bound variable __employees. I wonder if it's how I declared the variable? I did it like so: code [Bindable] private var __employees:ArrayCollection; public function get employees():ArrayCollection { return __employees; } public function set employees( employees:ArrayCollection ):void { if (employees != null) { __employees = employees; } } /code Maybe I should just make it public? Nope, that didn't work. I'm also wondering if the event.preventDefault(); is messing something up. Nope, that just prevents the the base class ListBase from doing it's DD handling. Since this doesn't check for duplicates, I don't want to use it. I'm not sure what to do --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui [EMAIL PROTECTED] wrote: Mx:DataGrid's change event is for when selection changes, not when the collection changes. Could that be the issue? collectionChange may be what you want. From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Friday, May 18, 2007 10:12 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? I don't have the code in front of me right now, but to be more precise, dgEmployees is not broadcasting a change event upon a DD action. I want dgEmployees to broadcast an event every time there is a change to the DataGrid. The dgEmployees DataGrid has a change event method defined, somthing like: code mx:DataGrid id=dgEmployees dataProvider={__employees} change=broadcastEvent(event) ... /code The broadcastEvent() method constructs a custom event containing the number of elements in the DataGrid, and then dispatches it to be used elsewhere. Now, as I type this, I see that I might have keyed off the wrong event, change. Not sure if that is broadcast upon a change in the dataProvider, BUT I had been working on this code previously (converting to Flex 2.0), and I believe that I saw this same issue. I noticed that when I used the debugger to step throught the doDragDrop() method, I was seeing that only the dataProvider was being updated, and not the ArrayCollection. I can't verify this until Monday (5/21), but I'm almost 100% sure this is what I saw. --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui aharui@ wrote: How do you know it didn't update __employees? Can you post a mini-example in a couple of screenfuls of text? From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Thursday, May 17, 2007 6:11 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Does Drag Drop Only Update the DataProvider? 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
[flexcoders] Re: Does Drag Drop Only Update the DataProvider?
Why is binding to private variables not recommended? Should I bind to the employees pseudo property? I figured out why it wasn't working. Binding is one way. I'm binging the DataGrids dataProvider to the ArrayCollection, so only changes to the ArrayCollection would effect the dataProvider. It doesn't work the other way around (changes to the DataProvider updating the ArrayCollection). Somehow I seemed to have forgotten that fact. --- In flexcoders@yahoogroups.com, Alex Harui [EMAIL PROTECTED] wrote: collectionChange is dispatched from the collection and not the DataGrid. Binding to private variables is not recommended, but not the problem either. Can you fit an entire example in two screens of text? If so, post it. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Sent: Monday, May 21, 2007 9:56 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? collectionChange doesn't appear to be a valid DataGrid event, but I tried dataChanged, added, add, valueCommit, and updateComplete. None of these did what I wanted, and actually, I have verified that the __employees ArrayCollection does not update after a DD event. Looking through everything in debug mode, I'm seeing that the dataProvider of the DataGrid is updated after DD, but not the bound variable __employees. I wonder if it's how I declared the variable? I did it like so: code [Bindable] private var __employees:ArrayCollection; public function get employees():ArrayCollection { return __employees; } public function set employees( employees:ArrayCollection ):void { if (employees != null) { __employees = employees; } } /code Maybe I should just make it public? Nope, that didn't work. I'm also wondering if the event.preventDefault(); is messing something up. Nope, that just prevents the the base class ListBase from doing it's DD handling. Since this doesn't check for duplicates, I don't want to use it. I'm not sure what to do --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui aharui@ wrote: Mx:DataGrid's change event is for when selection changes, not when the collection changes. Could that be the issue? collectionChange may be what you want. From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Friday, May 18, 2007 10:12 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? I don't have the code in front of me right now, but to be more precise, dgEmployees is not broadcasting a change event upon a DD action. I want dgEmployees to broadcast an event every time there is a change to the DataGrid. The dgEmployees DataGrid has a change event method defined, somthing like: code mx:DataGrid id=dgEmployees dataProvider={__employees} change=broadcastEvent(event) ... /code The broadcastEvent() method constructs a custom event containing the number of elements in the DataGrid, and then dispatches it to be used elsewhere. Now, as I type this, I see that I might have keyed off the wrong event, change. Not sure if that is broadcast upon a change in the dataProvider, BUT I had been working on this code previously (converting to Flex 2.0), and I believe that I saw this same issue. I noticed that when I used the debugger to step throught the doDragDrop() method, I was seeing that only the dataProvider was being updated, and not the ArrayCollection. I can't verify this until Monday (5/21), but I'm almost 100% sure this is what I saw. --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui aharui@ wrote: How do you know it didn't update __employees? Can you post a mini-example in a couple of screenfuls of text? From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Thursday, May 17, 2007 6:11 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Does Drag Drop Only Update the DataProvider? 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
RE: [flexcoders] Re: Does Drag Drop Only Update the DataProvider?
Binding just converts a variable into a property by wrapping in function get/set. The best practice to dispatch an event from the setter and declare the event name in the [Bindable] metadata. I thought there was a warning for binding to private, but maybe we got around it somehow. Binding is one way, but if the dg is bound to employees, the underlying array that got passed into the ArrayCollection should get modified when you drop into the dg. -Alex From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Sent: Monday, May 21, 2007 2:41 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? Why is binding to private variables not recommended? Should I bind to the employees pseudo property? I figured out why it wasn't working. Binding is one way. I'm binging the DataGrids dataProvider to the ArrayCollection, so only changes to the ArrayCollection would effect the dataProvider. It doesn't work the other way around (changes to the DataProvider updating the ArrayCollection). Somehow I seemed to have forgotten that fact. --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui [EMAIL PROTECTED] wrote: collectionChange is dispatched from the collection and not the DataGrid. Binding to private variables is not recommended, but not the problem either. Can you fit an entire example in two screens of text? If so, post it. From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Monday, May 21, 2007 9:56 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? collectionChange doesn't appear to be a valid DataGrid event, but I tried dataChanged, added, add, valueCommit, and updateComplete. None of these did what I wanted, and actually, I have verified that the __employees ArrayCollection does not update after a DD event. Looking through everything in debug mode, I'm seeing that the dataProvider of the DataGrid is updated after DD, but not the bound variable __employees. I wonder if it's how I declared the variable? I did it like so: code [Bindable] private var __employees:ArrayCollection; public function get employees():ArrayCollection { return __employees; } public function set employees( employees:ArrayCollection ):void { if (employees != null) { __employees = employees; } } /code Maybe I should just make it public? Nope, that didn't work. I'm also wondering if the event.preventDefault(); is messing something up. Nope, that just prevents the the base class ListBase from doing it's DD handling. Since this doesn't check for duplicates, I don't want to use it. I'm not sure what to do --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui aharui@ wrote: Mx:DataGrid's change event is for when selection changes, not when the collection changes. Could that be the issue? collectionChange may be what you want. From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Friday, May 18, 2007 10:12 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? I don't have the code in front of me right now, but to be more precise, dgEmployees is not broadcasting a change event upon a DD action. I want dgEmployees to broadcast an event every time there is a change to the DataGrid. The dgEmployees DataGrid has a change event method defined, somthing like: code mx:DataGrid id=dgEmployees dataProvider={__employees} change=broadcastEvent(event) ... /code The broadcastEvent() method constructs a custom event containing the number of elements in the DataGrid, and then dispatches it to be used elsewhere. Now, as I type this, I see that I might have keyed off the wrong event, change. Not sure if that is broadcast upon a change in the dataProvider, BUT I had been working on this code previously (converting to Flex 2.0), and I believe that I saw this same issue. I noticed that when I used the debugger to step throught the doDragDrop() method, I was seeing that only the dataProvider was being updated, and not the ArrayCollection. I can't verify this until Monday (5/21), but I'm almost 100% sure this is what I saw. --- In flexcoders@yahoogroups.com
[flexcoders] Re: Does Drag Drop Only Update the DataProvider?
I read (Migrating Applications to Flex 2 by Adobe, page 108) that if you have private variables with getter/setter, you can omit the event name as the compiler would automatically generate an event named propertyChanged. What that example shows that I didn't do is it put the [Bindable] metadata tag before the getter method, not the variable declaration. I'll change that in the future. Regarding your last statement, I would like to think that the bound ArrayCollection would update if you specifically update the dataProvider of the DataGrid, but according to what I'm seeing in the debugger, that isn't the case. I wish it were... It would've made my life a lot easier. BTW, thanks for your help. --- In flexcoders@yahoogroups.com, Alex Harui [EMAIL PROTECTED] wrote: Binding just converts a variable into a property by wrapping in function get/set. The best practice to dispatch an event from the setter and declare the event name in the [Bindable] metadata. I thought there was a warning for binding to private, but maybe we got around it somehow. Binding is one way, but if the dg is bound to employees, the underlying array that got passed into the ArrayCollection should get modified when you drop into the dg. -Alex From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Sent: Monday, May 21, 2007 2:41 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? Why is binding to private variables not recommended? Should I bind to the employees pseudo property? I figured out why it wasn't working. Binding is one way. I'm binging the DataGrids dataProvider to the ArrayCollection, so only changes to the ArrayCollection would effect the dataProvider. It doesn't work the other way around (changes to the DataProvider updating the ArrayCollection). Somehow I seemed to have forgotten that fact. --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui aharui@ wrote: collectionChange is dispatched from the collection and not the DataGrid. Binding to private variables is not recommended, but not the problem either. Can you fit an entire example in two screens of text? If so, post it. From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Monday, May 21, 2007 9:56 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? collectionChange doesn't appear to be a valid DataGrid event, but I tried dataChanged, added, add, valueCommit, and updateComplete. None of these did what I wanted, and actually, I have verified that the __employees ArrayCollection does not update after a DD event. Looking through everything in debug mode, I'm seeing that the dataProvider of the DataGrid is updated after DD, but not the bound variable __employees. I wonder if it's how I declared the variable? I did it like so: code [Bindable] private var __employees:ArrayCollection; public function get employees():ArrayCollection { return __employees; } public function set employees( employees:ArrayCollection ):void { if (employees != null) { __employees = employees; } } /code Maybe I should just make it public? Nope, that didn't work. I'm also wondering if the event.preventDefault(); is messing something up. Nope, that just prevents the the base class ListBase from doing it's DD handling. Since this doesn't check for duplicates, I don't want to use it. I'm not sure what to do --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui aharui@ wrote: Mx:DataGrid's change event is for when selection changes, not when the collection changes. Could that be the issue? collectionChange may be what you want. From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Friday, May 18, 2007 10:12 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? I don't have the code in front of me right now, but to be more precise, dgEmployees is not broadcasting a change event upon a DD action. I want dgEmployees to broadcast an event every time there is a change to the DataGrid. The dgEmployees DataGrid has a change
RE: [flexcoders] Re: Does Drag Drop Only Update the DataProvider?
There are two common bindable patterns: [Bindable] public var foo And [Bindable(someEvent)] public function get foo():... public function set foo(value:...) { _foo = value; dispatchEvent(new Event(someEvent)); } Otherwise, in your case you ended up generating two levels of get/set functions which is unnecessary. Feel free to post a mini-example of the DG update issue. Then we'll know for sure. -Alex From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Sent: Monday, May 21, 2007 4:08 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? I read (Migrating Applications to Flex 2 by Adobe, page 108) that if you have private variables with getter/setter, you can omit the event name as the compiler would automatically generate an event named propertyChanged. What that example shows that I didn't do is it put the [Bindable] metadata tag before the getter method, not the variable declaration. I'll change that in the future. Regarding your last statement, I would like to think that the bound ArrayCollection would update if you specifically update the dataProvider of the DataGrid, but according to what I'm seeing in the debugger, that isn't the case. I wish it were... It would've made my life a lot easier. BTW, thanks for your help. --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui [EMAIL PROTECTED] wrote: Binding just converts a variable into a property by wrapping in function get/set. The best practice to dispatch an event from the setter and declare the event name in the [Bindable] metadata. I thought there was a warning for binding to private, but maybe we got around it somehow. Binding is one way, but if the dg is bound to employees, the underlying array that got passed into the ArrayCollection should get modified when you drop into the dg. -Alex From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Monday, May 21, 2007 2:41 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? Why is binding to private variables not recommended? Should I bind to the employees pseudo property? I figured out why it wasn't working. Binding is one way. I'm binging the DataGrids dataProvider to the ArrayCollection, so only changes to the ArrayCollection would effect the dataProvider. It doesn't work the other way around (changes to the DataProvider updating the ArrayCollection). Somehow I seemed to have forgotten that fact. --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui aharui@ wrote: collectionChange is dispatched from the collection and not the DataGrid. Binding to private variables is not recommended, but not the problem either. Can you fit an entire example in two screens of text? If so, post it. From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Monday, May 21, 2007 9:56 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? collectionChange doesn't appear to be a valid DataGrid event, but I tried dataChanged, added, add, valueCommit, and updateComplete. None of these did what I wanted, and actually, I have verified that the __employees ArrayCollection does not update after a DD event. Looking through everything in debug mode, I'm seeing that the dataProvider of the DataGrid is updated after DD, but not the bound variable __employees. I wonder if it's how I declared the variable? I did it like so: code [Bindable] private var __employees:ArrayCollection; public function get employees():ArrayCollection { return __employees; } public function set employees( employees:ArrayCollection ):void { if (employees != null) { __employees = employees; } } /code Maybe I should just make it public? Nope, that didn't work. I'm also wondering if the event.preventDefault(); is messing something up. Nope, that just prevents the the base class ListBase from doing it's DD handling. Since this doesn't check for duplicates, I don't want to use it. I'm not sure what to do --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com
[flexcoders] Re: Does Drag Drop Only Update the DataProvider?
I don't have the code in front of me right now, but to be more precise, dgEmployees is not broadcasting a change event upon a DD action. I want dgEmployees to broadcast an event every time there is a change to the DataGrid. The dgEmployees DataGrid has a change event method defined, somthing like: code mx:DataGrid id=dgEmployees dataProvider={__employees} change=broadcastEvent(event) ... /code The broadcastEvent() method constructs a custom event containing the number of elements in the DataGrid, and then dispatches it to be used elsewhere. Now, as I type this, I see that I might have keyed off the wrong event, change. Not sure if that is broadcast upon a change in the dataProvider, BUT I had been working on this code previously (converting to Flex 2.0), and I believe that I saw this same issue. I noticed that when I used the debugger to step throught the doDragDrop() method, I was seeing that only the dataProvider was being updated, and not the ArrayCollection. I can't verify this until Monday (5/21), but I'm almost 100% sure this is what I saw. --- In flexcoders@yahoogroups.com, Alex Harui [EMAIL PROTECTED] wrote: How do you know it didn't update __employees? Can you post a mini-example in a couple of screenfuls of text? From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Sent: Thursday, May 17, 2007 6:11 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Does Drag Drop Only Update the DataProvider? 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
RE: [flexcoders] Re: Does Drag Drop Only Update the DataProvider?
Mx:DataGrid's change event is for when selection changes, not when the collection changes. Could that be the issue? collectionChange may be what you want. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Sent: Friday, May 18, 2007 10:12 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Does Drag Drop Only Update the DataProvider? I don't have the code in front of me right now, but to be more precise, dgEmployees is not broadcasting a change event upon a DD action. I want dgEmployees to broadcast an event every time there is a change to the DataGrid. The dgEmployees DataGrid has a change event method defined, somthing like: code mx:DataGrid id=dgEmployees dataProvider={__employees} change=broadcastEvent(event) ... /code The broadcastEvent() method constructs a custom event containing the number of elements in the DataGrid, and then dispatches it to be used elsewhere. Now, as I type this, I see that I might have keyed off the wrong event, change. Not sure if that is broadcast upon a change in the dataProvider, BUT I had been working on this code previously (converting to Flex 2.0), and I believe that I saw this same issue. I noticed that when I used the debugger to step throught the doDragDrop() method, I was seeing that only the dataProvider was being updated, and not the ArrayCollection. I can't verify this until Monday (5/21), but I'm almost 100% sure this is what I saw. --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui [EMAIL PROTECTED] wrote: How do you know it didn't update __employees? Can you post a mini-example in a couple of screenfuls of text? From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Geoffrey Sent: Thursday, May 17, 2007 6:11 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Does Drag Drop Only Update the DataProvider? 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