Back to Devexpress

GridView.TopRowIndex Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-fa8f8e35.md

latest6.4 KB
Original Source

GridView.TopRowIndex Property

Gets or sets the top visible row.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

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

Property Value

TypeDescription
Int32

An integer value representing the index of the top row visible.

|

Remarks

To scroll the View via code, you can assign a row’s visible index to the TopRowIndex property. The specified row will become the top visible row, if possible. Note that if the GridOptionsBehavior.SmartVertScrollBar option is disabled, any row within the View can be made top visible. For instance, you can assign the last visible row index to the TopRowIndex property and the row will actually become top visible row within the View. If the option mentioned is enabled, the View will be scrolled to the bottom possible position when the bottom visible row is at the bottom of the View.

Changing this property value raises the GridView.TopRowChanged event.

Please refer to the Rows topic for information on obtaining row visible indexes.

Note

In Embedded detail mode, the TopRowIndex property may return unexpected values when a detail View is open and is scrolled. In this case, the TopRowIndex property may refer to rows within detail Views. To check if the referred row belongs to a detail View, use the ColumnView.GetVisibleRowHandle along with the GridView.IsExternalRow method, as shown below:

csharp
int rowHandle = gridView1.GetVisibleRowHandle(gridView1.TopRowIndex);
//Check if the row belongs to a detail View:
if(gridView1.IsExternalRow(rowHandle)) {
    //...
}

Note

Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the TopRowIndex member must not be invoked for these Views. The TopRowIndex member can only be used with Views that display real data within the Grid Control. Use the following methods to access these Views with which an end user interacts at runtime.

The following code snippets (auto-collected from DevExpress Examples) contain references to the TopRowIndex 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.

winforms-preserve-grid-state-on-refresh/CS/RefreshHelperClass.cs#L127

csharp
public void SaveVisibleIndex(){
    visibleRowIndex = view.GetVisibleIndex(view.FocusedRowHandle) - view.TopRowIndex;
}

winforms-grid-auto-scroll-during-drag-drop/CS/AutoScrollTimer/AutoScrollHelper.cs#L95

csharp
if(GoDown)
    view.TopRowIndex++;
if(GoUp)

winforms-preserve-grid-state-on-refresh/VB/RefreshHelperClass.vb#L136

vb
Public Sub SaveVisibleIndex()
    visibleRowIndex = view.GetVisibleIndex(view.FocusedRowHandle) - view.TopRowIndex
End Sub

winforms-grid-auto-scroll-during-drag-drop/VB/AutoScrollTimer/AutoScrollHelper.vb#L120

vb
owner.ScrollIfNeeded()
If GoDown Then view.TopRowIndex += 1
If GoUp Then view.TopRowIndex -= 1

See Also

RowCount

TopRowChanged

PrevTopRowIndex

SmartVertScrollBar

TopRowPixel

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace