Back to Devexpress

TreeList.GetVisibleIndexByNode(TreeListNode) Method

windowsforms-devexpress-dot-xtratreelist-dot-treelist-dot-getvisibleindexbynode-x28-devexpress-dot-xtratreelist-dot-nodes-dot-treelistnode-x29.md

latest4.8 KB
Original Source

TreeList.GetVisibleIndexByNode(TreeListNode) Method

Returns the index of the specified node among the visible nodes.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

csharp
public int GetVisibleIndexByNode(
    TreeListNode node
)
vb
Public Function GetVisibleIndexByNode(
    node As TreeListNode
) As Integer

Parameters

NameTypeDescription
nodeTreeListNode

The TreeListNode object representing the node whose visible index is obtained.

|

Returns

TypeDescription
Int32

An integer value specifying the position of the specified node among the visible nodes.

|

Remarks

A node is implied invisible if it is a child of a collapsed node. The GetVisibleIndexByNode returns a zero or a greater value when the node is out of the Tree List’s viewable area due to the current scrolling position (see the TreeList.TopVisibleNodeIndex property). This method returns -1 in the cases listed below:

  • the specified node is null ( Nothing in Visual Basic);
  • the specified node is a child of a collapsed node.

Example

The sample code below demonstrates how to determine whether a user sees a given node within the Tree List’s scrollable area. The IsNodeVisibleOnScreen method returns false if the node is invisible or only partially visible at the bottom of the Tree List control.

csharp
private bool IsNodeVisibleOnScreen(DevExpress.XtraTreeList.Nodes.TreeListNode node) {
   DevExpress.XtraTreeList.TreeList tree = node.TreeList;
   int visibleIndex = tree.GetVisibleIndexByNode(node);
   return visibleIndex >= tree.TopVisibleNodeIndex && visibleIndex < 
     tree.TopVisibleNodeIndex + tree.ViewInfo.VisibleRowCount;
}
vb
Imports DevExpress.XtraTreeList.Nodes

Private Function IsNodeVisibleOnScreen(ByVal node As TreeListNode) As Boolean
   Dim tree As DevExpress.XtraTreeList.TreeList = node.TreeList
   Dim visibleIndex As Integer = tree.GetVisibleIndexByNode(node)
   Return visibleIndex >= tree.TopVisibleNodeIndex AND visibleIndex < _
     tree.TopVisibleNodeIndex + tree.ViewInfo.VisibleRowCount
End Function

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetVisibleIndexByNode(TreeListNode) method.

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.

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

csharp
if(topVisibleNode == null) topVisibleNode = TreeList.FocusedNode;
    TreeList.TopVisibleNodeIndex = TreeList.GetVisibleIndexByNode(topVisibleNode);
}

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

vb
End If
    TreeList.TopVisibleNodeIndex = TreeList.GetVisibleIndexByNode(topVisibleNode)
End Try

See Also

TopVisibleNodeIndex

GetNodeByVisibleIndex(Int32)

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace