Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
590
Drag and drop from TreeView item into xamDataGrid cell.
posted

Hello there. I would like to implement the ability to drag an item from a TreeView and drop it in a xamDataGrid cell. Is this something that is supported by infragistics? Eventually I'll have to make that xamDataGrid cell be a combo box with pre-populated entries so the user can either type their entry, select it from the combo box options OR drag and drop it from a seperate tree view. 

Thank you so much for any guidance! I recently translated from engineering where I was programming in Java to a software development group where I'm now programming in C#/WPF so even something like this that may sound basic to you isn't very apparent to me. 

  • 34690
    Offline posted

    Hello WpfDeveloper,

    In order to achieve this behavior of drag-and-drop from a TreeView to your XamDataGrid, I would recommend utilizing the Infragistics Drag and Drop Framework, which you can read about here: https://es.infragistics.com/help/wpf/drag-and-drop-framework.

    Doing this, you can define an ItemTemplate for your TreeView and place the DragSource on it, setting its IsDraggable property to false. You will also want to handle the Drop event, which I will explain a little later. This will allow your TreeView items to be dragged. I would also recommend writing a Style for CellValuePresenter and setting the attached DragDropManager.DropTarget property to a new DropTarget object, and mark its IsDropTarget property to true.

    Once this is done, in the Drop event, you can get the element that the DragSource is hooked to by casting e.OriginalDragSource, where e is the event arguments of the Drop event. You can also get the CellValuePresenter from e.DropTarget. The underlying data context of the CellValuePresenter elements is the DataRecord that owns it, and so I would recommend that you get this, either by utilizing the DataContext property or the Record property. These DataRecords have a DataItem property which return you your data item, and I would imagine that your underlying data item would have a property for the element you are dragging. Accessing the DataItem here will allow you to populate the cell with the information contained in the e.OriginalDragSource, as you can set the corresponding property associated with that cell. In the case that you are dragging and dropping to multiple cells, you can utilize the Field property of the CellValuePresenter to find out which property should be set on Drop.

    I have attached a sample project to demonstrate the above. I hope this helps you.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

    XDGDragFromTreeViewCase.zip