[Overview][Types][Classes][Procedures and functions][Index] | Reference for unit 'ShellCtrls' (#lcl)

# TCustomShellTreeView.CanExpand

Determines if the specified tree node can be expanded in the shell tree view control.

## Declaration

Source position: shellctrls.pas line 112

`protected function TCustomShellTreeView.CanExpand(`
`Node: TTreeNode`
`):Boolean; override;`

## Arguments

`Node` |  | Tree node examined in the method.

## Function result

True when the tree node can be expanded to display child nodes.

## Description

CanExpand is an overridden Boolean function used to determine if the specified tree node can be expanded in the shell tree view control. CanExpand ensures that the shell control reflects the current content in the local file system during execution of the method.

Node contains the TTreeNode examined and updated in the method.

CanExpand calls the inherited method to signal the OnExpanding event handler (when assigned). No additional actions are performed if the inherited method returns False.

CanExpand temporarily disables the AutoExpand functionality in the shell tree view control, and updates the child nodes in Node when needed. The value in ExpandCollapseMode is used to determine whether child nodes are created or recreated. The following actions are performed for the ExpandCollapseMode property values:

ecmRefreshedExpanding
  Deletes existing child nodes and calls PopulateTreeNodeWithFiles to reload entries for the path in Node.
ecmKeepChildren
  Keeps existing child nodes. Calls PopulateTreeNodeWithFiles if the existing child node count is 0 (zero).
ecmCollapseAndClear
  Calls PopulateTreeNodeWithFiles to load files for the path in Node.

The value in AutoExpand is restored to its original value prior to exiting from the method.

The entire update process is done in a BeginUpdate / EndUpdate block to reduce the number of screen refreshes in the method.

## Version info

Modified in LCL version 3.0 to use ExpandCollapseMode to control actions performed for child nodes.

## See also

TCustomShellTreeView.ExpandCollapseMode |  | Controls the actions performed when a tree node is expanded or collapsed on the control.
TCustomShellTreeView.PopulateTreeNodeWithFiles |  | Adds tree nodes for file system objects found starting at the specified node / path.
TShellTreeView.AutoExpand |  | Expands a tree node when it is clicked or activated in code.
TShellTreeNode |  | Represents tree nodes in TCustomShellTreeView / TShellTreeView.
TTreeNode
TCustomTreeView.AutoExpand |  | Expands a tree node when it is clicked or activated in code.