Forum Discussion

krkarthik_info's avatar
krkarthik_info
Frequent Contributor
8 years ago

How to do drag and drop a record from one position to another in Infragistics Xamdatagrid

Hi,

 

I have Infragistics.Windows.DataPresenter.XamDataGrid control with n number of records. I wanted to perform the scenario "Drag a record from index 2 to Drop it at index 0". 

 

How do I achieve this? Can someone help me out with this problem statement.

 

I have tried below methods

Grid.DataSource.MoveItem() and Grid.DataSource.Move().

 

But I wanted to perform drag and drop operation

 

Thanks,

Karthik K R

1 Reply

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Drag and drop us done by using the "Drag" method associated with most on screen objects (see https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/onscreen/drag-action-onscreen-object.html).

     

    The only problem I have with that is that it is very co-ordinate specific.  You drag from some point on the source object and then you drag a differential x and y distance.  So, you can't just say, "Drag this object to that object" using Drag alone...

     

    To that end...  with a little help from our friends here... I use the following:

    function dragCalculatedDistance(startObject, destinationObject) {
        var startPoint, targetPoint, dragX, dragY;
        // Drag from the center of object A to the center of object B
    
        startPoint = startObject.WindowToScreen(startObject.Width/2, startObject.Height/2);
        targetPoint = destinationObject.WindowToScreen(destinationObject.Width/2, destinationObject.Height/2);
    
        dragX = targetPoint.X - startPoint.X;
        dragY = targetPoint.Y - startPoint.Y;
    
        startObject.Drag(-1, -1, dragX, dragY); 
    }

    The startObject would be the OnScreen object (Alias or some other way of designating the onscreen object) that is the thing you want to drag, the destinationObject is the OnScreen object that is the target destination.