Search code examples
asp.net.net-4.0treeviewtreenodesystem.web.ui.webcontrols

How can I deselect the node or set the myTreeView.SelectedNode to null?


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?


Solution

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

    if (myTreeView.SelectedNode != null)
    {
        myTreeView.SelectedNode.Selected = false;
    }