Olá Ricado,
O que acontece é que como o DataGrid faz o Drag And Drop automático
para você este é um comportamento padrão. Mas graças ao parâmetro que
define a prioridade dos eventos você pode anular este comportamento.
Primeiro use isto no "creationCompleteHandler" do seu componente:
left_dg.addEventListener(KeyboardEvent.KEY_DOWN, keyDownDgHandler,
false, 10);
left_dg.addEventListener(DragEvent.DRAG_ENTER, dragEnterHandler,
false, 10);
left_dg.addEventListener(DragEvent.DRAG_OVER, dragOverHandler, false,
10);
right_dg.addEventListener(KeyboardEvent.KEY_DOWN, keyDownDgHandler,
false, 10);
right_dg.addEventListener(DragEvent.DRAG_ENTER, dragEnterHandler,
false, 10);
right_dg.addEventListener(DragEvent.DRAG_OVER, dragOverHandler, false,
10);
Agora adicione os seguintes event handlers no mesmo componente:
private function keyDownDgHandler(event:KeyboardEvent):void
{
cancelCtrlKey(event);
}
private function dragOverHandler(event:DragEvent):void
{
cancelCtrlKey(event);
}
private function dragEnterHandler(event:DragEvent):void
{
cancelCtrlKey(event);
}
private function cancelCtrlKey(event:Object):void
{
event.ctrlKey = false;
}
[]'s
Beck Novaes
On Feb 29, 4:11 pm, Ricardo Ramires <[EMAIL PROTECTED]> wrote:
> Pessoal, fiz um component para facilitar o gerenciamento de
> relacionamentos entre tabelas, onde tenho 2 datagrids e utilizo o drag
> and drop, com a propriedade dragMoveEnabled marcada como verdadeira,
> mas se eu apertar o control do teclado aparece o + junto com o cursor
> e a informacao fica duplicada... tem alguma maneira de desabilitar
> isso.
>
> segue o codigo:
>
> Simulacao da aplicacao:
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> xmlns:comp="*"
> layout="vertical"
> creationComplete="creationCompleteHandler()">
>
> <mx:Script>
> <![CDATA[
> import mx.collections.ArrayCollection;
>
> [Bindable] private var leftCollection:ArrayCollection;
> [Bindable] private var
> rightCollection:ArrayCollection;
>
> private function creationCompleteHandler():void
> {
> leftCollection = new ArrayCollection([
> {idTabela1 : 1, txt1 : "Texto
> 1 A", txt2 : "Texto 2 A"},
> {idTabela1 : 2, txt1 : "Texto
> 1 B", txt2 : "Texto 2 B"},
> {idTabela1 : 3, txt1 : "Texto
> 1 C", txt2 : "Texto 2 C"}
>
> ]);
>
> rightCollection = new ArrayCollection([
> {idTabela1 : 3, txt1 : "Texto
> 1 D", txt2 : "Texto 2 D"}
>
> ]);
> }
>
> ]]>
> </mx:Script>
>
> <comp:SetRelation
> typeRelation="all"
> dataProviderLeft="{leftCollection}"
> dataProviderRight="{rightCollection}">
>
> <comp:columnsLeft>
> <mx:DataGridColumn headerText="Texto 1"
> dataField="txt1" />
> </comp:columnsLeft>
>
> <comp:columnsRight>
> <mx:DataGridColumn headerText="Texto 2"
> dataField="txt2" />
> </comp:columnsRight>
> </comp:SetRelation>
>
> </mx:Application>
>
> component (SetRelation):
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
> creationComplete="creationCompleteHandler()">
>
> <mx:Component id="leftButtonRenderer">
> <mx:HBox horizontalAlign="center" verticalAlign="middle">
> <mx:LinkButton label="»" id="remove_btn" toolTip=""/>
> </mx:HBox>
> </mx:Component>
>
> <mx:Component id="rightButtonRenderer">
> <mx:HBox horizontalAlign="center" verticalAlign="middle">
> <mx:LinkButton label="«" id="remove_btn" toolTip=""/>
> </mx:HBox>
> </mx:Component>
>
> <mx:Script>
> <![CDATA[
>
> import mx.controls.Button;
> import mx.controls.dataGridClasses.DataGridColumn;
> import mx.controls.listClasses.ListBase;
> import mx.managers.DragManager;
> import mx.controls.DataGrid;
> import mx.events.DragEvent;
> import mx.collections.ArrayCollection;
>
> [Bindable] private var dragable:Boolean = false;
>
> // type
> [Bindable] private var _typeRelation:String = "all";
> public function get typeRelation():String
> {
> return _typeRelation;
> }
> public function set typeRelation(type:String):void
> {
> _typeRelation = type;
> if(_typeRelation == "all" || _typeRelation ==
> "drag" ) dragable =
> true;
> }
>
> private function getButtonLeftColumn():DataGridColumn
> {
> var buttonColumn:DataGridColumn = new
> DataGridColumn("");
> buttonColumn.width = 28;
> buttonColumn.sortable = false;
> buttonColumn.itemRenderer =
> leftButtonRenderer;
> return buttonColumn;
> }
>
> private function getButtonRightColumn():DataGridColumn
> {
> var buttonColumn:DataGridColumn = new
> DataGridColumn("");
> buttonColumn.width = 28;
> buttonColumn.sortable = false;
> buttonColumn.itemRenderer =
> rightButtonRenderer;
> return buttonColumn;
> }
>
> // left
> [Bindable] public var
> dataProviderLeft:ArrayCollection;
> [Bindable] public var _columnsLeft:Array;
> public function get columnsLeft():Array
> {
> return _columnsLeft;
> }
> public function set columnsLeft(columns:Array):void
> {
> if(_typeRelation == "all" || _typeRelation ==
> "add")
> columns.push(getButtonLeftColumn());
> _columnsLeft = columns;
> }
>
> // right
> [Bindable] public var
> dataProviderRight:ArrayCollection;
> [Bindable] public var _columnsRight:Array;
> public function get columnsRight():Array
> {
> return _columnsRight;
> }
> public function set columnsRight(columns:Array):void
> {
> if(_typeRelation == "all" || _typeRelation ==
> "add")
> columns.unshift(getButtonRightColumn());
> _columnsRight = columns;
> }
>
> private function creationCompleteHandler():void
> {
> addEventListener(FocusEvent.FOCUS_IN,
> focusInHandler);
> addEventListener(FocusEvent.FOCUS_OUT,
> focusOutHandler);
>
> left_dg.addEventListener(MouseEvent.CLICK,
> removeItem);
> right_dg.addEventListener(MouseEvent.CLICK,
> removeItem);
>
>
> //left_dg.addEventListener(KeyboardEvent.KEY_DOWN,
> keyDownDgHandler);
>
> //right_dg.addEventListener(KeyboardEvent.KEY_DOWN,
> keyDownDgHandler);
> }
>
> /* private function
> keyDownDgHandler(event:KeyboardEvent):void
> {
> DragManager.showFeedback(DragManager.MOVE);
> } */
>
> override protected function
> focusInHandler(event:FocusEvent):void
> {
> left_dg.dragEnabled = dragable;
> left_dg.dropEnabled = dragable;
> left_dg.dragMoveEnabled = dragable;
> right_dg.dragEnabled = dragable;
> right_dg.dropEnabled = dragable;
> right_dg.dragMoveEnabled = dragable;
> }
> override protected function
> focusOutHandler(event:FocusEvent):void
> {
> left_dg.dragEnabled = false;
> left_dg.dropEnabled = false;
> left_dg.dragMoveEnabled = false;
> right_dg.dragEnabled = false;
> right_dg.dropEnabled = false;
> right_dg.dragMoveEnabled = false;
> }
>
> public function removeItem(event:MouseEvent):void
> {
> //trace("removeItem: " +
> event.currentTarget.id);
>
> var dgTarget:DataGrid =
> DataGrid(event.currentTarget);
>
> if(event.target is Button && event.target.id
> == "remove_btn")
> {
> switch(event.currentTarget.id)
> {
> case "right_dg" :
>
> dataProviderLeft.addItem(dgTarget.selectedItem);
>
> dataProviderRight.removeItemAt(dgTarget.selectedIndex);
> break;
> case "left_dg" :
>
> dataProviderRight.addItem(dgTarget.selectedItem);
>
> dataProviderLeft.removeItemAt(dgTarget.selectedIndex);
> break;
> }
> }
> }
>
> ]]>
> </mx:Script>
>
> <mx:DataGrid id="left_dg"
> dataProvider="{dataProviderLeft}"
> columns="{_columnsLeft}"/>
>
> <mx:DataGrid id="right_dg"
> dataProvider="{dataProviderRight}"
> columns="{_columnsRight}"/>
>
> </mx:HBox>
>
> Grato,
>
> Ricardo Ramires
--~--~---------~--~----~------------~-------~--~----~
Você recebeu esta mensagem porque está inscrito na lista "flexdev"
Para enviar uma mensagem, envie um e-mail para [email protected]
Para sair da lista, envie um email em branco para [EMAIL PROTECTED]
Mais opções estão disponíveis em http://groups.google.com/group/flexdev
-~----------~----~----~----~------~----~------~--~---