Reputation: 113
I have this code to select first node of TreeView. But when page loads the by default root node is other than first, I want to set the selected node as top most by default. Here is my code in page load but it's not working:
Dim nodes As TreeNodeCollection = TreeView1.Nodes
If nodes.Count > 0 Then
' Select the root node
TreeView1.SelectedNode = nodes(0)
End If
This gives the blue underline error on this line:
TreeView1.SelectedNode = nodes(0)
The error is:
"Selected Node Property is read Only"
Please any one tell me how can I do this?
Upvotes: 2
Views: 18727
Reputation: 7350
List<ARTICLE_REVIEW> reviewList = eb.ArticleReviewGetByUserOID(long.Parse(Session["User_OID"].ToString()));
treeReviews.Nodes.Clear();
foreach (ARTICLE_REVIEW review in reviewList)
{
TreeNode stepNode = new TreeNode();
stepNode.Value = review.ID.ToString();
stepNode.Text = review.TITLE;
treeReviews.Nodes.Add(stepNode);
treeReviews.ExpandAll();
// Set the root node to be selected
treeReviews.Nodes[0].Selected = true;
}
Upvotes: 0
Reputation: 3751
In ASP.Net .SelectedNode is readonly you can only get but not set it using this property. You can use Node.Selected = true or Node.Selected = false to achive the same functionality!
Try this:
Dim nodes As TreeNodeCollection = TreeView1.Nodes
If nodes.Count > 0 Then
' Select the root node
nodes(0).Selected = true
End If
Upvotes: 0
Reputation: 5251
To select a node you need to set the selected property on the node itself:
nodes(0).Selected = true
Equally you can use:
nodes(0).Select()
Upvotes: 2
Reputation: 2064
nodes(0).Selected
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treenode.select.aspx
Upvotes: 0