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

Treeview

3 Answers 115 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Albert
Top achievements
Rank 1
Albert asked on 08 May 2012, 03:16 PM
Using the following legacy code using telerik Q2 2009 winform controls.  This code moves the selected node down on a button click.  We are upgrading to Q1 2012 what is the equivalent code.  Q1 2012 there is no FirstVisibleNode or ScrollPosition.Y etc.

Any help greatly appreciated.
Dim sNode As RadTreeNode = tv.SelectedNode
 
 
If sNode Is Nothing Then
    tv.SelectedNode = tv.FirstVisibleNode
    Exit Sub
End If
Dim nextVisible = sNode.NextVisibleNode
Dim vb As Integer
If nextVisible IsNot Nothing Then
    tv.SelectedNode = nextVisible
    vb = tv.ClientRectangle.Y - tv.ScrollPosition.Y + tv.ClientRectangle.Height
    If nextVisible.Bounds.Bottom > vb Then
        tv.ScrollBy(-1)
    End If
    tv.Nodes.Move(sNode.Index, nextVisible.Index)
ElseIf sNode.Index = tv.Nodes.Count - 1 Then
    nextVisible = tv.Nodes(0)
    tv.SelectedNode = nextVisible
    vb = tv.ClientRectangle.Y - tv.ScrollPosition.Y + tv.ClientRectangle.Height
    If nextVisible.Bounds.Bottom > vb Then
        tv.ScrollBy(-1)
    End If
    tv.Nodes.Move(sNode.Index, nextVisible.Index)
    tv.BringIntoView(sNode)
End If
sNode.Selected = True

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 11 May 2012, 01:53 PM
Hello Albert,

Thank you for contacting us.

I am not sure that I fully understand what this code does. So, I just replaced the old methods with the new ones. Here is the code:
Private Sub radButton1_Click(sender As Object, e As EventArgs)
    Dim node As RadTreeNode = tv.SelectedNode
    If node Is Nothing Then
        tv.SelectedNode = FirstVisibleNode(tv)
        Return
    End If
    Dim nextVisibleNode As RadTreeNode = node.NextNode
    If nextVisibleNode IsNot Nothing Then
        tv.SelectedNode = nextVisibleNode
    ElseIf node.Index = tv.Nodes.Count - 1 Then
        node = tv.Nodes(0)
        node.Selected = True
        node.EnsureVisible()
    End If
End Sub
 
Public Function FirstVisibleNode(tv As RadTreeView) As RadTreeNode
    If tv.TreeViewElement.ViewElement.Children.Count > 0 Then
        Dim nodeElement As TreeNodeElement = DirectCast(tv.TreeViewElement.ViewElement.Children(0), TreeNodeElement)
        Return nodeElement.Data
    End If
    Return Nothing
End Function

If it is not working properly, please describe the exact behavior that you want to achieve. I will be glad to help further.

I am looking forward to your reply.
 
Kind regards,
Jack
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Albert
Top achievements
Rank 1
answered on 11 May 2012, 02:50 PM
Thanks Jack for the reply. I did get this working.
The code moved the selected Node either up or down the tree depending on the Button click. For example if the user clicked the UP button.
Dim sNode As RadTreeNode = tv.SelectedNode
        Dim prevNodeIndex As Integer = tv.SelectedNode.Index - 1
 
        If prevNodeIndex < 0 Then prevNodeIndex = tv.Nodes.Count - 1
        tv.Nodes.Move(sNode.Index, prevNodeIndex)
        tv.BringIntoView(sNode)
        sNode.Selected = True

Thanks again.
0
Jack
Telerik team
answered on 15 May 2012, 12:26 PM
Hi Albert,

I am glad to hear that you have found a solution for this issue. If you have any other questions, do not hesitate to contact us.
 
Regards,
Jack
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
Treeview
Asked by
Albert
Top achievements
Rank 1
Answers by
Jack
Telerik team
Albert
Top achievements
Rank 1
Share this question
or