Forum Discussion

zelenskya's avatar
zelenskya
Occasional Contributor
13 years ago

Drag action fails from time to time

Hello!

I'm using Drag action for dragging nodes of Infragistic ultratree control. It works fine during debug & mostly fails during playback.

I've tried to set delay before Drag action execution and also played with Project delays (dragging delay, etc.) - nothing works.



Please, advise. Thanks!



In my script I do the following:

1. Select start node and finish one, expand them if necessary (works stable).

2. Get nodes' bounds.

3. Calculate start/finish points (left+width/2;top+height/2).

4. Calculate moving distance.

5. Call Drag action applying it to tree control.

4 Replies

  • Hi,



    How exactly do you call Drag and what coordinates do you pass to it? Also, do you drag within the same control, or do you drag to a different control?



    Try using the function below. Does it work?



    function DragTreeItem(treeControl, itemName, destControl)

    {

    var destX = destControl.Width / 2;

    var destY = destControl.Height / 2;

    var destPoint = destControl.WindowToScreen(destX, destY);



    treeControl.ClickItem(itemName); // You may need to insert your code which gets item bounds here instead of ClickItem



    LLPlayer.MouseDown(MK_LBUTTON, Sys.Desktop.MouseX, Sys.Desktop.MouseY, 0);

    LLPlayer.MouseMove(destPoint.x, destPoint.y, 200);

    LLPlayer.MouseUp(MK_LBUTTON, destPoint.x, destPoint.y, 200);

    }

    ...

    var tree = ...//Obtain the tree view

    var target = ...//Obtain the dragging action's target



    DragTreeItem(tree, "|RootNode1|SubNode1|SubNode2", target);

    ...

  • zelenskya's avatar
    zelenskya
    Occasional Contributor
    Hi, thanks for your answer!



    I'm trying to drag tree nodes within the same control (ultre tree). So that I call Drag method for tree control: tree.Drag(X, Y, deltaX, deltaY)

    where (X, Y) - source tree node coordinates (nodeDrag.Bounds.Left+nodeDrag.Bounds.Width/2; nodeDrag.Bounds.Top+nodeDrag.Bounds.Height/2);

             (DeltaX,DeltaY) - the difference between destination tree node and source tree node. Tree nodes are properly identified and clicked - it can be seen during playback. So that I guess coordinates are correct.



    I also tried to adopt your code for my script and it looks like no effect (I can't see any actions during playback).










  • Hi,



    The function I posted should grab the target item and place the mouse pointer to the destination control with the left button down. Then, release the button. It actually doesn't produce any visual movement. However, it is strange that it doesn't drag anything, probably, the function doesn't suit here.



    What happens if you try something like this?

    function DragTreeItem(treeControl, itemName, deltaX, deltaX)

    {

    treeControl.ClickItem(itemName);

    var destPoint = treeControl.WindowToScreen(Sys.Desktop.MouseX + deltaX, Sys.Desktop.MouseY + deltaX);



    LLPlayer.MouseDown(MK_LBUTTON, Sys.Desktop.MouseX, Sys.Desktop.MouseY, 0);

    LLPlayer.MouseMove(destPoint.x, destPoint.y, 200);

    LLPlayer.MouseUp(MK_LBUTTON, destPoint.x, destPoint.y, 200);

    }




    Also, if you need to drag an item to another node in the same tree, you can modify this code to get coordinates of the destination item. You can do this in the same way - call ClickItem on it and convert window coordinates to screen with the WindowToScreen method. Does this above function change the mouse position (if it still doesn't help)?



    BTW, is the destination point visible when dragging?
  • zelenskya's avatar
    zelenskya
    Occasional Contributor
    Dear Jared,

    thank you for your help! It looks like WindowToScreen function was the key. Everything works fine and stable now. I don't mean Drag action but your way with LLPlayer functions.