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:
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.
| Private Sub RadTreeView1_DragEnded(ByVal sender As Object, ByVal 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.

