I am trying to implement drag and drop functionality in XAMDataGrid, I am able to append new items to the grid but I want to "insert" new item at a postion on which mouse has dropped the item.
Can you help me to get the index of record in grid where mouse has just dropped new item.
Hello,
You can get the DataRecordPresenter element. It is the visual representation of the DataRecord. The Record exposes an Index property:
dataRecordPresenter.Record.Index
You can use the Infragistics.Windows.Utilities.GetAncestor/GetDescendant~FromType methods to get the DataRecordPresenter which is directly below the mouse.
Hope this helps.
Thanks for quick reply!
this is what i have done...
delegate...
this
.DataGrid.MouseMove += OnMouseMove;
and the function...
private void OnMouseMove(object sender, System.Windows.Input.MouseEventArgs e) // this is a mouse over event handler for XamDataGrid
{
DependencyObject source = e.MouseDevice.DirectlyOver as DependencyObject;
DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(source, typeof(DataRecordPresenter), true) as DataRecordPresenter;
if (drp == null) { return; }
indexUnderDragCursorInDataGrid = drp.Record.Index; } But new item is getting inserted at any random position! If I set indexUnderDragCursorInDataGrid to let say 2, then every new dragged in item is getting inserted at positon 2. it works correctly, means there is no problem with record insertion logic. I think MouseMove is not correct event in which I am identifying index. Please suggest.
indexUnderDragCursorInDataGrid = drp.Record.Index;
} But new item is getting inserted at any random position! If I set indexUnderDragCursorInDataGrid to let say 2, then every new dragged in item is getting inserted at positon 2. it works correctly, means there is no problem with record insertion logic. I think MouseMove is not correct event in which I am identifying index.
Please suggest.
I am not sure why the index is not changing. Maybe you should clear it after the drag-drop is complete/or started new drag-drop.
You can see a simple implementation of mine on drag-drop here or in my profile's attached files ( I believe here is the updated version ) and find it useful to solve your problem.