0

I am working on an online web application written in C# and I am using System.Web.UI.WebControls.TreeView

The treeview is represented by an asp:TreeView tag embedded on the webpage.

its weird, I'm using .NET Framework 4, and if I try something like

myTreeView.SelectedNode = null 

then it states " cannot be assigned to -- it is read-only"

Could you please assist? How can I deselect the node or set the myTreeView.SelectedNode to null?

crazyTech
  • 1,379
  • 3
  • 32
  • 67

2 Answers2

3

Here is the code that I used to ensure that the SelectedNode was Deselected:

if (myTreeView.SelectedNode != null)
{
    myTreeView.SelectedNode.Selected = false;
}
crazyTech
  • 1,379
  • 3
  • 32
  • 67
0

Works too

if (myTreeView.SelectedNode.IsSelected)
{
    myTreeView.SelectedNode = null;
}
Jonny
  • 73
  • 7