Question

I have a TreeView web control on an ASP page. I am programmatically populating all the tree nodes. I want to disable the link on ALL tree nodes. I can do it one at a time, like this (using a string array for simplicity's sake):

for each (string strValue in strValues)
{
TreeNode objNode = new TreeNode(strValue);
objNode.SelectAction = TreeNodeSelectAction.None;
objTreeView.Nodes.Add(objNode);
}

Assume for the sake of argument that I have multiple level of nodes, so there is not a simple way to iterate through all nodes once I am done populating. Is there a property I can set on the TreeView to set SelectAction for all nodes?

Était-ce utile?

La solution

TreeView does not support any property to do this. However you can do it by using recursive methods

Autres conseils

This should solve your problem:

    protected void Page_Load(object sender, EventArgs e)
    {
        processNode(trvTest.Nodes);
    }

    private void processNode(TreeNodeCollection nodes)
    {
        foreach (TreeNode node in nodes)
        {
            node.SelectAction = TreeNodeSelectAction.None;
            if (node.ChildNodes.Count > 0)
                processNode(node.ChildNodes);
        }
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top