Back to Devexpress

TreeList.FocusedNode Property

windowsforms-devexpress-dot-xtratreelist-dot-treelist-ab1adf68.md

latest7.2 KB
Original Source

TreeList.FocusedNode Property

Gets or sets the focused node.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

csharp
[Browsable(false)]
public TreeListNode FocusedNode { get; set; }
vb
<Browsable(False)>
Public Property FocusedNode As TreeListNode

Property Value

TypeDescription
TreeListNode

A TreeListNode object representing the focused node. null ( Nothing in Visual Basic) if no node is focused.

|

Remarks

The FocusedNode property allows you to determine the currently focused node or to move node focus. Note also that assigning an existing node to the FocusedNode property makes the specified node visible on screen. This may result in scrolling and expanding collapsed parent nodes.

When node focus changes, the TreeList.FocusedNodeChanged event is raised.

If you assign an invisible node (TreeListNode.Visible) to the FocusedNode property, the property resets to the null value.

Example

The following example shows how to move focus to a specific node. To do this, the requried node is assigned to the TreeList.FocusedNode property.

csharp
// Move focus to the first root node.
treeList1.FocusedNode = treeList1.Nodes[0];
vb
' Move focus to the first root node.
TreeList1.FocusedNode = TreeList1.Nodes(0)

The following code snippets (auto-collected from DevExpress Examples) contain references to the FocusedNode property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

excel-export-api-examples/CS/XLExportExamples/Form1.cs#L144

csharp
{
    SpreadsheetExample example = treeList1.GetDataRecordByNode(treeList1.FocusedNode) as SpreadsheetExample;
    if (example == null)

winforms-treelist-save-restore-expanded-state-of-nodes/CS/TreeListViewState.cs#L49

csharp
}
TreeList.FocusedNode = TreeList.FindNodeByKeyID(focused);
foreach(object key in selected) {

word-document-api-examples/CS/Form1.cs#L84

csharp
if (treeList1.Nodes.Count > 0)
    treeList1.FocusedNode = treeList1.MoveFirst().FirstNode;
RichEditExample example = treeList1.GetDataRecordByNode(treeList1.FocusedNode) as RichEditExample;

winforms-treelist-customize-node-menu/CS/Form1.cs#L31

csharp
private void bbAddChild_ItemClick(object sender, EventArgs e) {
    TreeListNode newNode = treeList1.AppendNode(null, treeList1.FocusedNode);
    newNode.SetValue(0, "New Node");

xaf-win-enable-inplace-editing-in-tree-list-view/CS/EFCore/TreeListInplaceEF/TreeListInplaceEF.Win/Controllers/TreeListAppearanceControllerEx.cs#L17

csharp
TreeList tl = (TreeList)sender;
ObjectTreeListNode node = tl.FocusedNode as ObjectTreeListNode;
if (node == null) return;

excel-export-api-examples/VB/XLExportExamples/Form1.vb#L143

vb
Private Sub RunExample(ByVal filePath As String, ByVal documentFormat As XlDocumentFormat)
   Dim example As SpreadsheetExample = TryCast(treeList1.GetDataRecordByNode(treeList1.FocusedNode), SpreadsheetExample)
   If example Is Nothing Then

winforms-treelist-save-restore-expanded-state-of-nodes/VB/TreeListViewState.vb#L54

vb
Next key
TreeList.FocusedNode = TreeList.FindNodeByKeyID(focused)
For Each key As Object In selected

word-document-api-examples/VB/Form1.vb#L80

vb
treeList1.ExpandAll()
If treeList1.Nodes.Count > 0 Then treeList1.FocusedNode = treeList1.MoveFirst().FirstNode
Dim example As RichEditExample = TryCast(treeList1.GetDataRecordByNode(treeList1.FocusedNode), RichEditExample)

winforms-treelist-customize-node-menu/VB/Form1.vb#L33

vb
Private Sub bbAddChild_ItemClick(ByVal sender As Object, ByVal e As EventArgs)
    Dim newNode As TreeListNode = treeList1.AppendNode(Nothing, treeList1.FocusedNode)
    newNode.SetValue(0, "New Node")

winforms-richeditcontrol-common-api/VB/RichEditAPISample/Form1.vb#L455

vb
If treeList1.Nodes.Count > 0 Then
    treeList1.FocusedNode = treeList1.MoveFirst().FirstNode
End If

See Also

Nodes

BeforeFocusNode

FocusedNodeChanged

SetFocusedNode(TreeListNode)

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace