4

I've been using hardcoded hyperlinks for my web app navigation, but the app has grown since and managing it is becoming a real pain. I've decided to replace what I have with the TreeView control, however I want to make several changes to the way it looks.

Is there any property that needs to be set, that would allow user to expand the TreeView node by clicking its text instead of +/- ? I've already set ShowExpandColapse to 'false'.

I want my final result to end up as something similar to the TreeView on the left of the MSDN site.

Could anyone point me at the right direction please?

4 Answers 4

8

Set TreeNode.SelectAction to either Expand, or SelectExpand.

Sign up to request clarification or add additional context in comments.

2 Comments

I've had no luck with this. Could it be that TreeNode.SelectAction gets fired when the +/- icon for the node gets clicked (instead of the text)? Maybe JavaScript would be a better way to go about solving this problem.
@Dr.Greenthumb : Can you provide an example how to write a javascript to solve this.My requirement is Show only parent nodes by default, When user click on parent node(text itself), then show the child nodes.
3

you can use xml data source or direct binding from db to treview

in the TreeView DataBound event we can write d recursive function as below to fetch each node and assign expand action to them.

 protected void TreeView1_DataBound(object sender, EventArgs e)
{

    foreach (TreeNode node in TreeView1.Nodes)
    {
        node.SelectAction = TreeNodeSelectAction.Expand;
        PrintNodesRecursive(node);
    }
}


    public void PrintNodesRecursive(TreeNode oParentNode)
    {


      // Start recursion on all subnodes.
     foreach(TreeNode oSubNode in oParentNode.ChildNodes)
  {
    oSubNode.SelectAction = TreeNodeSelectAction.Expand;
  PrintNodesRecursive(oSubNode);
  }
 }

1 Comment

in this case you can use OnTreeNodeDataBound instead of recursion.... OnTreeNodeDataBound(object sender, TreeNodeEventArgs e) {e.Node.SelectAction = TreeNodeSelectAction.SelectExpand;}
0

I think you just have to do this in code: handle the Click event, determine the currently-selected tree node, and toggle its Expanded property (I think that's what it's called here).

3 Comments

I've added the following code to master page codebehind: protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { TreeView1.SelectedNode.SelectAction = TreeNodeSelectAction.Expand; } However the nodes are still not expanding. Must be something I'm missing here.
Also, I was wondering how would you handle nodes that have NavigateURL as ""? They don't appear as links in the TreeView.
Sorry, didn't realize this was an ASP.NET question. I have no clue.
0

You can do this only this way! http://geekswithblogs.net/rajiv/archive/2006/03/16/72575.aspx

With respect, Alexander

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.