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

How can i expand all nodes

5 Answers 77 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jorge
Top achievements
Rank 1
Jorge asked on 23 Oct 2008, 05:33 PM
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.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Oct 2008, 05:44 AM
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.
0
Jorge
Top achievements
Rank 1
answered on 24 Oct 2008, 02:46 PM
Thanks for your help, but don't work. 
Always the count is 0 and the treeview has data.
0
Veselin Vasilev
Telerik team
answered on 24 Oct 2008, 02:50 PM
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.
0
Jorge
Top achievements
Rank 1
answered on 24 Oct 2008, 02:57 PM
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.
0
Veselin Vasilev
Telerik team
answered on 24 Oct 2008, 02:59 PM
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.
Tags
TreeView
Asked by
Jorge
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jorge
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or