I have been looking for a solution that could reorder or move nodes up and down using a button as trigger. But I have no luck finding it. Does anyone have any idea about this? Or this is just a dead end?
I have been looking for a solution that could reorder or move nodes up and down using a button as trigger. But I have no luck finding it. Does anyone have any idea about this? Or this is just a dead end?
I just figured this on the other forum. Here's what I came up with.
The only problem with this is that if you try to move the parent node, the children won't follow.![]()
Private Sub cmdDown_Click() MoveDown End Sub Private Sub cmdUP_Click() MoveUp End Sub Function MoveUp() Dim nodX As Node, Node As Node Dim i As Integer, nodPos As Long Dim SkipNode As Boolean Dim myMessage As VbMsgBoxResult Dim tvSelObj As MSComctlLib.TreeView Dim tempNodeText As String On Error GoTo ErrHandler Set tvSelObj = frmDataVal.tvSelectedDVs If tvSelObj.SelectedItem Is Nothing Then Exit Function nodPos = 1 For i = 0 To tvSelObj.Nodes.Count SkipNode = False If i = tvSelObj.SelectedItem.Index Then If i = nodPos Then SkipNode = True nodPos = nodPos + 1 If SkipNode = False Then tempNodeText = tvSelObj.SelectedItem.Previous.Text tvSelObj.Nodes(tvSelObj.SelectedItem.Previous.Index).Text = tvSelObj.Nodes(tvSelObj.SelectedItem.Index).Text tvSelObj.Nodes(tvSelObj.SelectedItem.Index).Text = tempNodeText tvSelObj.SelectedItem.Selected = False tvSelObj.SelectedItem.Previous.Selected = True End If End If Next ErrHandler: End Function Function MoveDown() Dim nodX As Node, Node As Node Dim i As Integer, nodPos As Long, parentCount As Integer Dim SkipNode As Boolean Dim myMessage As VbMsgBoxResult Dim tvSelObj As MSComctlLib.TreeView Dim tempNodeText As String On Error GoTo ErrHandler Set tvSelObj = frmDataVal.tvSelectedDVs If tvSelObj.SelectedItem Is Nothing Then Exit Function nodPos = 1 For i = tvSelObj.Nodes.Count To 0 Step -1 SkipNode = False If i = tvSelObj.SelectedItem.Index Then If i = nodPos Then SkipNode = True nodPos = nodPos + 1 If SkipNode = False Then tempNodeText = tvSelObj.SelectedItem.Next.Text tvSelObj.Nodes(tvSelObj.SelectedItem.Next.Index).Text = tvSelObj.Nodes(tvSelObj.SelectedItem.Index).Text tvSelObj.Nodes(tvSelObj.SelectedItem.Index).Text = tempNodeText tvSelObj.SelectedItem.Selected = False tvSelObj.SelectedItem.Next.Selected = True End If End If Next ErrHandler: End Function
![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks