package
{
import mx.controls.DataGrid;
public class CustomDataGrid extends DataGrid
{
import mx.controls.listClasses.IListItemRenderer;
import flash.events.MouseEvent;
public function mouseEventToItemRenderer2(event:MouseEvent):IListItemRenderer {
return mouseEventToItemRenderer(event);
}
}
}
Then I was able to use that in my function quite easily:
import mx.controls.listClasses.IListItemRenderer;
var r:IListItemRenderer = dragInitiator.mouseEventToItemRenderer2 (e);
if (!(r == null) && !(r is DataGridItemRenderer)) {
// do dragging stuff here, etc.
DragManager.doDrag(dragInitiator, ds, e, renderer,
r.measuredWidth-dragInitiator.contentMouseX, r.measuredHeight-dragInitiator.contentMouseY);
Now I just need to control for the mouse button going down in a non-cell and being moved into a cell. I'll post that code when I get it.
On 7/20/06, Pan Troglodytes <[EMAIL PROTECTED]> wrote:
Ok, I'm trying to make my dragged grid item look a certain way and am running into two problems. I'm dragging a grid row to a list. But I don't want the default behavior of the giant grid row. I want my own custom drag widget and I want it to pop up with its bottom right point at the current cursor position. I have yet to be able to accomplish the latter. Second, I want the dragging to start only when the mouse is actually clicked on the grid row. With the code I have, it starts it if you select an item and then click and drag down in the blank area of the grid.
Here is some source code that basically shows what I'm doing. It is not my actual source code, because that has a ton of other irrelevant crap. But it does replicate the experience pretty closely. I have commented out the part where I'm trying to figure out what to set the X/Y to. If you have some wild guesses, I'd suggest trying them before posting. ;) Believe me, I've thought of about a dozen things (like subtracting the renderers width off the X - won't work cause it isn't set) and all have been dead ends.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.controls.DataGrid;
import mx.controls.Label ;
import mx.containers.Canvas;
import mx.collections.ArrayCollection;
import mx.core.DragSource;
import mx.managers.DragManager;
[Bindable] public var provider:ArrayCollection = new ArrayCollection([{label:"one"}, {label:"two"}, {label:"three four five"}]);
private function startGridDrag(event:MouseEvent):void {
if (event.buttonDown) {
var dragInitiator:DataGrid = DataGrid(event.currentTarget);
var ds:DragSource = new DragSource();
var row:Object = dragInitiator.selectedItem;
if (row != null) {
var draggedItem:Object = {label:row.label};
var renderer:Canvas = new Canvas;
var lbl:Label = new Label;
renderer.addChild(lbl);
lbl.text = row.label;
//renderer.x = ????
//renderer.y = ????
ds.addData([draggedItem], 'items');
DragManager.doDrag(dragInitiator, ds, event, renderer);
}
}
}
]]>
</mx:Script>
<mx:DataGrid id="grid" dataProvider="{provider}" width="200" height="200" mouseMove="startGridDrag(event)">
<mx:columns>
<mx:DataGridColumn headerText="label">
<mx:itemRenderer>
<mx:Component>
<mx:Canvas>
<mx:Label text="{ data.label}" color="blue"/>
</mx:Canvas>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:List dropEnabled="true" width="200" height="200"/>
</mx:Application>
--
Jason
--
Jason __._,_.___
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
| Web site design development | Computer software development | Software design and development |
| Macromedia flex | Software development best practice |
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

