What does your event listener code on the datagrids look like?
up to now I've been trying to use a drag to a garbage can image for removal of a row. In the dragAndDrop handler code I have:
sComponentName = String(event.dragInitiator);
which gives me the name of the control as a string but not a reference to the actual control so I can get at the data provider which is what I really need.
I don't want to use this model to manipulate rows in the grid selected because it is limited to just deletes. I want the user to select a row and then choose one of many operations using buttons - Delete, Add After, Add Before, Edit etc.
1 person found this helpful
What I'm looking for is a line that will look something like:
(may not be click--in your case it looks like probably not).
I was trying to give you a very precise solution that you could just use without needing to understand why it works or dig through extra information (not to mention saving myself some typing). But without that information, here is what I can tell you:
100% of Event subclasses have 2 properties:
If you are listening directly to the dataGrid, then you will find a reference to it in currentTarget. If you are NOT listening directly to dataGrid, target may or may not contain a reference to the dataGrid (it could also contain a reference, for instance, to a label in an itemRenderer). If you are not listening directly to dataGrid, you will need to loop on the parent of the target until you find a dataGrid or run out of parents.
this is beginning to to get me on the road to a viable solution.
If I were to add an event listener for each datagrid would it be ok to use the same event listener for each?
Could I then reference the dataprovider and row through say
currentTarget.dataProvider or currentTarget.dataProvider.seletectedIndex or currentTarget.dataProvider.getItemAt(currentTarget.dataProvider.seletectedIndex)
or something along theres lines?
Probably the best way would be for the user to first indicate what she wants to do by pressing a button, e.g. [Delete] and the after selecting a row in one of the datagrids the eventHandler would delete the marked row.
1 person found this helpful
OK, let's back up a bit. I was in a bit of a rush this morning, and didn't have time to check the reference.
If you don't do String(event.dragInitiator) but instead do
var dg:DataGrid = event.dragInitiator as DataGrid
you should get a reference to the DataGrid that is perfectly valid.
next, you can get a reference to the item that was dragged (you shouldn't care about the row per se) by doing this:
var ds:DragSource = event.dragSource;
var item:YourItemType = ds.dataForFormat('items') as YourType;
then, to delete:
var lcv:ListCollectionView = dg.dataProvider as ListCollectionView;
You can also probably get a reference to the datagrid by using event.currentTarget if your dragInitiator was showing a reference to the datagrid.
your post is opening a lot of windows...
So if I go the eventListener route and wait for the user to push a button (action) and mark a row in dg1 to dg7 then I can get
at the dataGrid/dataProvider in the listener, right? Should be very similar to the drag EventHandler in your example.
This sound like just what I need.
The button's event listener is not likely to have a reference to the Datagrid in it, so you will probably need to have logic in the listener for each button that identifies the correct DG.