Event fired before selection moves to another tree item; return value determines if selection can leave current tree item.

Parameters

none

Property of

TreeView

Description

Use canChange to prevent focus from moving to another item in the tree unless certain conditions are met. The canChange event handler can either return a value of true, which allows the focus to move, or false, which prevents the focus change.

The event handler usually uses the tree view’s selected property to get the currently selected tree item. Note that if no tree item is selected, the property contains null, so your event handler must check for that. In particular, when deleting a tree item, the focus must move to another tree item, and the currently selected item has just been deleted, and therefore selected will be null.