Back to Devexpress

How to: Prevent a specific node from being focused

windowsforms-5684-controls-and-libraries-tree-list-examples-focus-and-selection-how-to-prevent-a-specific-node-from-being-focused.md

latest825 B
Original Source

How to: Prevent a specific node from being focused

  • Nov 13, 2018

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