Back to Devexpress

TreeList.BeforeFocusNode Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-254a67f6.md

latest3.7 KB
Original Source

TreeList.BeforeFocusNode Event

Fires before a node is focused.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
public event BeforeFocusNodeEventHandler BeforeFocusNode
vb
Public Event BeforeFocusNode As BeforeFocusNodeEventHandler

Event Data

The BeforeFocusNode event's data class is BeforeFocusNodeEventArgs. The following properties provide information specific to this event:

PropertyDescription
CanFocusGets or sets a value indicating whether focus is allowed to be moved.
NodeGets the current Tree List node. Inherited from NodeEventArgs.
OldNodeGets the previously focused Tree List node. Inherited from FocusedNodeChangedEventArgs.

Remarks

The TreeList raises the BeforeFocusNode event each time a node is about to lose focus. The previously and currently focused nodes can be identified by the event parameter’s NodeEventArgs.Node and FocusedNodeChangedEventArgs.OldNode properties, respectively. The BeforeFocusNodeEventArgs.CanFocus property specifies whether the node can be focused. To prevent node focus changing, set this property to false.

Once the focused node has been changed, the TreeList raises the TreeList.FocusedNodeChanged and TreeList.AfterFocusNode events.

Note

We do not recommend to expand or collapse a node in the BeforeFocusNode event handler.

Example

The following example prohibits focusing the first node within the control, by handling the TreeList.BeforeFocusNode event.

csharp
private void treeList1_BeforeFocusNode(object sender, 
DevExpress.XtraTreeList.BeforeFocusNodeEventArgs e) {
   if (e.Node.Id == (sender as TreeList).Nodes[0].Id) 
      e.CanFocus = false;
}
vb
Private Sub TreeList1_BeforeFocusNode(ByVal sender As Object, 
ByVal e As DevExpress.XtraTreeList.BeforeFocusNodeEventArgs) 
Handles TreeList1.BeforeFocusNode
   If e.Node.Id = TryCast(sender, TreeList).Nodes(0).Id Then
      e.CanFocus = False
   End If
End Sub

See Also

AfterFocusNode

FocusedNodeChanged

FocusedNode

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace