Documentation for this section has not yet been entered.
Use the TreeNode.Expanded property to specify or determine whether the node is expanded.
You can expand and collapse a node by calling the TreeNode.Expand and TreeNode.Collapse methods, respectively. You can also expand and collapse a node and all its child nodes by calling the TreeNode.ExpandAll and TreeNode.CollapseAll methods, respectively.
Since the TreeNode.Expanded property is a tri-state property, the following C# code snippet causes a compile error:
Example
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { if (TreeView1.Nodes[0].Expanded) { // some work here } }
While VB.Net implicitly casts the Boolean value to a NullableBoolean, C# does not. Therefore, it is a best practice to explicitly check the state of the property. For example, the following code examples in Visual Basic and C# explicitly test the value of the TreeNode.Expanded property.
The following Visual Basic code example explicitly tests the value of the TreeNode.Expanded property. This example tests if the TreeNode.Expanded property is set to True; therefore Nothing and False fall through the If statement.
Example
If TreeView1.Nodes(0).Expanded = True Then 'some work hereEnd IF
This C# code example explicitly tests the value of the TreeNode.Expanded property. This example tests if the TreeNode.Expanded property is set to True; therefore Null and False fall through the If statement.
Example
if( TreeView1.Nodes[0].Expanded == true ) { //some work here}