---
title: "Expandable TreeView Node in C#"  
description: "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"  
author: "zhang wei"  
published: 2012-04-02  
updated: 2018-06-11  
canonical: https://www.mindstick.com/articles/898/expandable-treeview-node-in-c-sharp  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# 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 shwing your interest in this article.

\

---

Original Source: https://www.mindstick.com/articles/898/expandable-treeview-node-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
