Is this really what has to be done to clear the selection of an ASP.NET TreeView? I have a TreeView called myTreeView. I want to be able to write a single statement after which myTreeView.SelectedNode is null, but TreeView.SelectedNode doesn't have a setter. I've looked at the decompiled source of TreeView, and there is a SetSelectedNode method (that can accept null), but it's internal.

So I made this extension method:

public static void ClearSelection(this TreeView treeView)
{
    var currentSelection = treeView.SelectedNode;
    if (currentSelection != null)
    {
        currentSelection.Selected = false;
    }
}


and now I can just say

myTreeView.ClearSelection();


But this seems insane. Am I missing something?
There's no in-built method to do this. Your extension method looks great.

Even if TreeView did have an obscurely-named method to clear its selected node, I can only imagine it doing exactly the same as what you've written anyway.