开发者

How to expand .NET TreeView node by clicking its text instead of +/-

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 开发者_如何学Chave 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?


Set TreeNode.SelectAction to either Expand, or SelectExpand.


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);
  }
 }


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).


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

With respect, Alexander

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜