How can i expand all nodes

6 posts, 0 answers
  1. Jorge
    Jorge avatar
    8 posts
    Member since:
    Oct 2008

    Posted 23 Oct 2008 Link to this post

    I used a code like this to load my data:


     Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
                If Not Page.IsPostBack Then
                    LoadRootNodes()
                End If
            End Sub

     Private Sub LoadRootNodes()
       Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("TelerikConnectionString").ConnectionString)
    Dim selectCommand As New SqlCommand("SELECT * FROM Nodes WHERE ParentId IS NULL", connection)
                Dim adapter As New SqlDataAdapter(selectCommand)
                Dim data As New DataTable()
                adapter.Fill(data)

                For Each row As DataRow In data.Rows
                    Dim node As New RadTreeNode()
                    node.Text = row("Text")
                    node.Value = row("Id")
                    node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
                    RadTreeView1.Nodes.Add(node)
                Next
            End Sub


            Protected Sub RadTreeView1_NodeExpand(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs) Handles RadTreeView1.NodeExpand

                Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("TelerikConnectionString").ConnectionString)

                Dim selectCommand As New SqlCommand("SELECT Nodes.Id AS NodeId, Nodes.Text AS NodeText, COUNT(Children.Id) AS ChildCount FROM Nodes LEFT JOIN Nodes As Children ON Nodes.Id = Children.ParentId WHERE Nodes.ParentId = @parentId GROUP BY Nodes.Id, Nodes.Text", connection)

                selectCommand.Parameters.AddWithValue("parentId", e.Node.Value)
                Dim adapter As New SqlDataAdapter(selectCommand)
                Dim data As New DataTable()
                adapter.Fill(data)

                For Each row As DataRow In data.Rows
                    Dim node As New RadTreeNode()
                    node.Text = row("NodeText")
                    node.Value = row("NodeId")
                    If CInt(row("ChildCount")) > 0 Then
                        node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
                    End If
                    e.Node.Nodes.Add(node)
                Next
                e.Node.Expanded = True
            End Sub





    But I need expland all my nodes when I load the page. How can I expland all nodes without use the event RadTreeView1_NodeExpand.


    Thanks.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Oct 2008 Link to this post

    Hi,

    Try the following code snippet to achieve the desired scenario.

    VB:
    Protected Sub RadTreeView1_PreRender(sender As Object, e As EventArgs) 
        For Each myNode As RadTreeNode In RadTreeView1.GetAllNodes() 
            If myNode.Nodes.Count > 0 Then 
                myNode.Expanded = True 
            End If 
        Next 
    End Sub 
     


    Thanks
    Shinu.
  3. Jorge
    Jorge avatar
    8 posts
    Member since:
    Oct 2008

    Posted 24 Oct 2008 Link to this post

    Thanks for your help, but don't work. 
    Always the count is 0 and the treeview has data.
  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 24 Oct 2008 Link to this post

    Hello Jorge,

    You cannot expand a node which ExpandMode is ServerSideCallBack from the server-side code. You can expand it either with mouse expand or calling the expand() method.

    Kind regards,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Jorge
    Jorge avatar
    8 posts
    Member since:
    Oct 2008

    Posted 24 Oct 2008 Link to this post

    Thanks your help Veselin Vasilev, your said tha i can use expand method, but the child node are created in the RadTreeView1_NodeExpand event, if I call the expand method don't work because for the moment i dont have childnode.
  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 24 Oct 2008 Link to this post

    Hi Jorge,

    you need to call the expand method of the root node in order to fire the NodeExpand server event and then the children will be added.

    Greetings,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top