Home > DeveloperSection > Articles > Expandable TreeView Node in C#

Expandable TreeView Node in C#


ASP.Net ASP.Net 
Ratings:
2 Comment(s)
 5154  View(s)
Rate this:

Expandable TreeView Node in C#

In this article I’m going to explain how to make expandable treeview node in C# when others node is closed. Here I’m just creating a method to perform this task with name TreeView1_TreeNodeExpanded. Let’s take a look of this method code:

Foreground code:

<asp:TreeView ID="TreeView1" runat="server" ExpandDepth="0" OnTreeNodeExpanded="TreeView1_TreeNodeExpanded" ShowLines="True">

Code-behind:

protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)

         {

              TreeNodeCollection ts = null;

             if (e.Node.Parent == null)

             {

                 ts = ((TreeView)sender).Nodes;

             }

             else

                 ts = e.Node.Parent.ChildNodes;

             foreach (TreeNode node in ts)

             {

                 if (node != e.Node)

                 {

                     node.Collapse();

                 }

             }

         }

 

Thanks for showing your interest in this article.

 


Expandable TreeView Node in C#

By Haider M Rizvi on   4 years ago
Hi zhang wei,

Welcome to our MindStick Developers Section. Here you can share your knowledge to help others.

You cannot upload same content in more than one section, if its done then only one of them will be approved.

Looking forward for more Articles/Blogs from your side.

Thanks.

Haider M Rzvi

By zhang wei on   4 years ago

Hi Haider M Rzvi,thank you for help me,my english not well ,I belive i can to do more better!

I very Thanks!


Don't want to miss updates? Please click the below button!

Follow MindStick