This is a migrated thread and some comments may be shown as answers.

Drag, Drop, and IndexOf

3 Answers 88 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Special Ed
Top achievements
Rank 1
Special Ed asked on 16 Jun 2009, 01:39 AM
I am populating a treeview control from a database. I want to allow the user to drag and drop nodes to arrange the nodes in a sort order. I was trying to use the DragEnded event to get the new position in the tree and update the new position in the database. I thought I could use the IndexOf to get the new position in the tree the node is located. If I drag a root node the Items.IndexOf for the dragged node returns the correct position, lower level nodes return -1. The code I am using is as follows:

    Private Sub RadTreeView1_DragEnded(ByVal sender As ObjectByVal e As Telerik.Windows.Controls.RadTreeViewDragEndedEventArgs) Handles RadTreeView1.DragEnded  
 
        Dim newSortOrder As Integer 
        Dim parentId As Integer 
 
        Dim draggedItem As RadTreeViewItem = e.DraggedItems(0)  
        Dim eStore As eStoreDataDataContext = New eStoreDataDataContext  
 
        If IsNothing(draggedItem.ParentItem) Then 
            ' no parent then item is root node  
            parentId = 0  
        Else 
            parentId = draggedItem.ParentItem.Tag.ToString  
        End If 
 
        newSortOrder = RadTreeView1.Items.IndexOf(draggedItem)  
 
        MsgBox("parentId = " & parentId.ToString)  
        MsgBox("newSortOrder = " & newSortOrder.ToString)  
 
    End Sub 
 


 I am using the tag property to identify the parentId value in my database table. Does anyone know why the Items.IndexOf returns a number corresponding to the order the item is displayed in the tree for root node items and -1 for all other nodes?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 16 Jun 2009, 08:27 AM
Hello Special Ed,

You can use the TargetDropItem and to get its Index property. This, combined with the DropPosition property of the event args you can calculate the new index of the item.

You will need to get the latest internal build, because there is a fix that sets properly the TargetDropItem.

Please let us know if you need more info on that.

Regards,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Special Ed
Top achievements
Rank 1
answered on 16 Jun 2009, 02:54 PM

When you say calculate are you referring to the index being a 0 base collection. The index I would want in my example would be the index returned plus 1.

 

Ed

0
Kiril Stanoev
Telerik team
answered on 17 Jun 2009, 02:01 PM
Hi Special Ed,

I have attached an example demonstrating how you can retrieve the index property of the dropped item.
Please have a look at it and if you have any questions or comments, let us know.

Kind regards,
Kiril Stanoev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
Special Ed
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Special Ed
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Share this question
or