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

[Solved] set tree view selectedvalue

1 Answer 149 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
appdev
Top achievements
Rank 1
appdev asked on 08 Feb 2010, 02:38 PM
Dim rs As SqlDataReader = something 
Dim dt As New DataTable 
 dt.Load(rs) 
RadTreeView1.DataSource = dt 
RadTreeView1.DataTextField = dt.Columns("descriptions").ToString 
RadTreeView1.DataValueField = dt.Columns("sections").ToString 
RadTreeView1.DataBind() 
 
RadTreeView1.SelectedNode.Value = "somthing" always tells me that object reference is nothing can you tell me why or how do i set it to select the first value in the tree view. also if the first node in treeview is expandable, how do i expand it and then select the first child node in that parent node. thank you 
 
RadTreeView1.SelectedNode.Value = "somthing" always tells me that object reference is nothing can you tell me why or how do i set it to select
 the first value in the tree view. also if the first node in treeview is expandable, how do i expand it and then select the first child node in that parent node. thank you 

1 Answer, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 08 Feb 2010, 02:58 PM
The basic way to select the first node would be the following:

RadTreeView1.Nodes(0).Selected = True 

Since your approach is trying to access the SelectedNode and set it's value to "something". Since you haven't selected a node you are receiving this error.

As for selecting the first child item of the root node you can do this:
If RadTreeView1.Nodes(0).Nodes.Count > 0 Then 
    RadTreeView1.Nodes(0).Expanded = True 
    RadTreeView1.Nodes(0).Nodes(0).Selected = True 
End If 

Tags
TreeView
Asked by
appdev
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Share this question
or