By default, when you select a node in WebTreeView, the node will
be expanded. However, you can also set WebTreeView to collapse when the expanded
node is selected.
The default value of AllowExpandNodeOnSelect is True
and AllowCollapseNodeOnSelect is False.
In this topic, you will learn how to customize expand and collapse.
To expand and collapse by selecting the nodes.
- Bind WebTreeView to XMLDataSource.
- Set WebTreeView's properties >> AllowCollapseNodeOnSelect
to True.
- If both properties are set to False, simply double clicking the node to expand and
collapse.
To expand and collapse the selected node
- Bind WebTreeView to XMLDataSource.
- Drag 2 HTML buttons to the WebForm.
- Button1 will perform expanding selected node with
Expand() method.
- Button2 will perform collapsing selected node with Collapse()
method.
// Add this code to Expand selected node's button
function Button1_onclick()
{
var tv = ISGetObject("WebTreeView1");
if (tv.GetSelectedNode()!=null)
{
tv.GetSelectedNode().Expand();
}
else
alert("Please select a node first !");}
// Add this code to Collapse selected node's button
function Button2_onclick()
{
var tv = ISGetObject("WebTreeView1");
if (tv.GetSelectedNode()!=null)
{
tv.GetSelectedNode().Collapse();
}
else
alert("Please select a node first !");
}
|
- Run the application and try to click each button to see the result. For more
information, please refer to Expand and Collapse Node
sample in LiveSamples >> WebTreeView >> Expand Collapse Behaviors.
To toggle expand collapse of the selected node
- Bind WebTreeView to XMLDataSource.
- Drag a HTML button to the WebForm.
- The button will perform toggle expand collapse of the selected
node with ToggleExpandCollapse() method.
// Add this code to Toggle expand collapse selected node's button
function Button1_onclick()
{
var tv = ISGetObject("WebTreeView1");
if (tv.GetSelectedNode()!=null)
{
tv.GetSelectedNode().ToggleExpandCollapse();
}
else
alert("Please select a node first !");
}
|
- Run the application and try to click each button to see the result. For more
information, please refer to Expand and Collapse Node
sample in LiveSamples >> WebTreeView >> Expand Collapse Behaviors.
To expand and collapse all nodes
- Bind WebTreeView to XMLDataSource.
- Drag 2 HTML buttons to the WebForm.
- Button1 will perform expanding all nodes with
ExpandAll() method.
- Button2 will perform collapsing nodes with CollapseAll()
method.
// Add this code to Expand all nodes's button
function Button1_onclick()
{
var tv = ISGetObject("WebTreeView1");
tv.ExpandAll();
}
// Add this code to Collapse all nodes's button
function Button2_onclick()
{
var tv = ISGetObject("WebTreeView1");
tv.CollapseAll();
}
|
- Run the application and try to click each button to see the result. For more
information, please refer to Expand and Collapse Node
sample in LiveSamples >> WebTreeView >> Expand Collapse Behaviors.