Treeview

4 posts, 0 answers
  1. Code7
    Code7 avatar
    19 posts
    Member since:
    May 2009

    Posted 08 May 2012 Link to this post

    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
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 11 May 2012 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Code7
    Code7 avatar
    19 posts
    Member since:
    May 2009

    Posted 11 May 2012 Link to this post

    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.
  5. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 15 May 2012 Link to this post

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