Drag, Drop, and IndexOf

4 posts, 0 answers
  1. Special Ed
    Special Ed avatar
    2 posts
    Member since:
    Apr 2003

    Posted 15 Jun 2009 Link to this post

    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.
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 16 Jun 2009 Link to this post

    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.
  3. Special Ed
    Special Ed avatar
    2 posts
    Member since:
    Apr 2003

    Posted 16 Jun 2009 Link to this post

    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

  4. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 17 Jun 2009 Link to this post

    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.
Back to Top