Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   uso de OnDragOver y OnGragDrop, en un TreeView (https://www.clubdelphi.com/foros/showthread.php?t=50388)

spyfenix 15-11-2007 23:23:58

uso de OnDragOver y OnGragDrop, en un TreeView
 
que tal gente
tengo mi TreeView y tengo el siguiente codigo, segun yo sirve para arrastrar los nodos dentro del mismo TreeView pero lo tengo y no me deja realizar lo que quiero, alguien sabra que onda con este codigo:

Código:

procedure TfrmCuentasContables.trvCuentasDragDrop(Sender, Source: TObject;
  X, Y: Integer);
var
  AnItem: TTreeNode;
  AttachMode: TNodeAttachMode;
  HT: THitTests;
begin
  if TrvCuentas.Selected = nil then
  Exit;
  HT := trvCuentas.GetHitTestInfoAt(X, Y) ;
  AnItem := TrvCuentas.GetNodeAt(X, Y) ;
  if (HT - [htOnItem, htOnIcon, htNowhere, htOnIndent]<> HT) then
  begin
    if (htOnItem in HT) or
        (htOnIcon in HT) then
        AttachMode := naAddChild
    else if htNowhere in HT then
        AttachMode := naAdd
    else if htOnIndent in HT then
        AttachMode := naInsert;
        TrvCuentas.Selected.
        MoveTo(AnItem, AttachMode) ;
  end;
end;

procedure TfrmCuentasContables.trvCuentasDragOver(Sender, Source: TObject;
  X, Y: Integer; State: TDragState; var Accept: Boolean);
var
  TargetNode, SourceNode : TTreeNode;
begin
  TargetNode := TrvCuentas.GetNodeAt(X, Y);
  //acepta arrastrar desde el mismo
  If (Source = Sender) and (TargetNode <> nil) Then
  begin
    Accept := True;
    //determina origen y destino
    SourceNode := TrvCuentas.Selected;
    //Busca la cadena padre destino
    while (TargetNode.Parent <> nil) and (TargetNode <> SourceNode) do
      TargetNode := TargetNode.Parent;
      //Si se encuentra el origen
      if TargetNode = SourceNode Then
        //no permine el arrastre a un nodo hijo
        Accept := False;
    end
    else
      Accept := False;
  end;

espero me puedan ayudar

muchas gracias

Caro 16-11-2007 16:34:28

Hola spyfenix, he probado tu codigo y funciona bien, puede ser que solo te falte que la propiedad DragMode de tu TreeView este en dmAutomatic.

Saluditos

spyfenix 16-11-2007 20:10:34

que tal Caro
muchas gracias por tu respuesta, y si era eso, pero segun yo ya lo habia puesto, pero no guarde y cuando lo cheque estama manual, solo lo puse automatico y listo.
aa que detallitos los que nos sacan canas

gracias, saludos


La franja horaria es GMT +2. Ahora son las 05:49:50.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi