views:

9

answers:

0

Hi,

I have been implementing the drag and drop on the xceed grid. Code is below:

private void Grid_MouseMove(object sender, MouseEventArgs e) { Xceed.Wpf.DataGrid.DataGridControl grid = sender as Xceed.Wpf.DataGrid.DataGridControl; object target = GetItemAtLocation(sender, e.GetPosition((IInputElement)sender));

        //Dont initiate if the terminal is not Active
        if (target is CustomerBase &&

!((CustomerBase)target).Active) return;

        if (e.LeftButton == MouseButtonState.Pressed && target !=

null) { DragDrop.DoDragDrop(grid, target, DragDropEffects.Move);

        }
    }

object GetItemAtLocation(object sender, Point location) { object foundItem = null; HitTestResult hitTestResults = VisualTreeHelper.HitTest((Visual)sender, location);

        if (hitTestResults != null && hitTestResults.VisualHit is

FrameworkElement) { object dataObject = (hitTestResults.VisualHit as FrameworkElement).DataContext;

            if ((dataObject as CustomerBase) != null)
            {
                foundItem = dataObject;
            }
        }


        return foundItem;
    }

the problem with the above code, 60% the GetItemAtLocation will return one or two row below of the selected item.

can anyone please help?