Drag&drop in TreeViewAdv

Hello,
I'm implementing Drag&drop in TreeViewAdv and I have two requirements I cant find out how to solve:
  1. When moving an item to another node it needs to be always added as last child.
    I was playing around with DragTreeViewItemAdvEventArgs.DropIndex in DragEnd event but it seems to have no effect. How can this be done?
  2. I need to do some validation before moving nodes - sometimes move operation is not allowed based on target and dragged items. In DragEnd events it is OK, I can cancel the operation when not allowed. But I would like to do it rather in DragOver event to be able to show the user that operation is not allowed (change Effects to None), but in this event TargetOverItem is always null, so I'm not able to do the check I need. How can I get target item in DragOver event? What is TargetOverItem for?

Thank you for your help.

Ondřej Svoboda

3 Replies

VR Vijayalakshmi Roopkumar Syncfusion Team February 27, 2018 05:51 PM UTC

Hi Ondrej

Thank you for contacting Syncfusion Support

Query #1: When moving an item to another node it needs to be always added as last child.

By default, on dragging the item from one node to another node, it will add as last child only.The item would get dragged based on the dropping position. If we dropped the dragged item in center of treeviewitem, the item would be added in that position. So can you please brief us in which scenario or the purpose of your requirement to add the dragged item as a last child? It would be helpful for us to proceed further on this.

Query #2: How can I get target item in DragOver event? What is TargetOverItem for?

From your update we come to know that your requirement is to allow drag and drop based on the target items and dragged items. To check for the dropped items, you can use the PreviewDragOver event of TreeviewAdv. In this you can get the target items using e.source value. In this sample, we have checked for the particular node and allowed dropping of the items. Please download the sample for the same.

Sample: https://www.syncfusion.com/downloads/support/forum/136067/ze/TreeViewDragDropSample-1556902899 
Please try this solution and let us know if it is helpful.

Regards
Vijayalakshmi V.R.  



OS Ondrej Svoboda February 28, 2018 09:00 AM UTC

Query #1: When moving an item to another node it needs to be always added as last child.

By default, on dragging the item from one node to another node, it will add as last child only. This is OK.
The item would get dragged based on the dropping position. If we dropped the dragged item in center of treeviewitem, the item would be added in that position. I need to somehow override this behaviour so items are always dropped to the last position even if dragged in center of treeviewitem.

Query #2: How can I get target item in DragOver event? What is TargetOverItem for?

Thank you for the sample, I will test it.


VR Vijayalakshmi Roopkumar Syncfusion Team March 5, 2018 05:24 PM UTC

Hi Ondrej, 
Thank you for the patience.

Query #1: When moving an item to another node, it needs to be always added as last child?

We have checked the TreeViewAdv drag drop support and we currently can't change the index of the item while drop. So, we can't add the item at last while dropping between the item.

Regards
Vijayalakshmi V.R 


Loader.
Up arrow icon