Back to Devexpress

CustomColumnDisplayTextEventArgs.ListSourceRowIndex Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-customcolumndisplaytexteventargs-fc684d4b.md

latest6.3 KB
Original Source

CustomColumnDisplayTextEventArgs.ListSourceRowIndex Property

Gets the index in the data source of the row that contains the cell currently being processed.

Namespace : DevExpress.XtraGrid.Views.Base

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
public int ListSourceRowIndex { get; }
vb
Public ReadOnly Property ListSourceRowIndex As Integer

Property Value

TypeDescription
Int32

An integer value that is the row’s index in the data source. Note that row handles are not data source indexes.

|

Remarks

Use the ListSourceRowIndex property to identify the record in the data source that contains the currently processed cell. If this row index refers to a valid row (see below), you can use the ColumnView.GetListSourceRowCellValue method to obtain the row’s other cell values.

This property returns the same value for both Auto Filter and New Item rows. If you need to show custom strings in these rows’ cells, use the GridView.CustomDrawCell event instead.

csharp
private void Gv_CustomDrawCell(object sender, XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
    if (e.RowHandle == GridControl.AutoFilterRowHandle)
        e.DisplayText = "AutoFilterRow";
    if (e.RowHandle == GridControl.NewItemRowHandle)
        e.DisplayText = "NewItemRow";
}
vb
Private Sub Gv_CustomDrawCell(ByVal sender As Object, ByVal e As XtraGrid.Views.Base.RowCellCustomDrawEventArgs)
    If e.RowHandle = GridControl.AutoFilterRowHandle Then
        e.DisplayText = "AutoFilterRow"
    End If
    If e.RowHandle = GridControl.NewItemRowHandle Then
        e.DisplayText = "NewItemRow"
    End If
End Sub

When the ColumnView.CustomColumnDisplayText event is called to provide cell display text for a group row, the ListSourceRowIndex property will match the data source index of the first data row that follows the group row.

When the ColumnView.CustomColumnDisplayText event is called to customize filter values in a column’s Filter DropDown, the ListSourceRowIndex property returns the GridControl.InvalidRowHandle constant. In this case, it is not possible to determine the currently processed row, and therefore obtain other cell values.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ListSourceRowIndex 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-dashboard-custom-items/CS/TutorialsCustomItems/CustomItems/SimpleTableItem.cs#L61

csharp
DashboardFlatDataSource data = (DashboardFlatDataSource)grid.DataSource;
    e.DisplayText = data.GetDisplayText(e.Column.FieldName, e.ListSourceRowIndex);
}

winforms-dashboard-trend-line-indicators/CS/WinformsIndicator/Program.cs#L59

csharp
DashboardFlatDataSource data = (DashboardFlatDataSource)grid.DataSource;
    e.DisplayText = data.GetDisplayText(e.Column.FieldName, e.ListSourceRowIndex);
}

winforms-dashboard-custom-items/VB/TutorialsCustomItems/CustomItems/SimpleTableItem.vb#L62

vb
Dim data As DashboardFlatDataSource = DirectCast(grid.DataSource, DashboardFlatDataSource)
    e.DisplayText = data.GetDisplayText(e.Column.FieldName, e.ListSourceRowIndex)
End Sub

winforms-dashboard-trend-line-indicators/VB/WinformsIndicator/Program.vb#L67

vb
Dim data As DashboardFlatDataSource = CType(grid.DataSource, DashboardFlatDataSource)
    e.DisplayText = data.GetDisplayText(e.Column.FieldName, e.ListSourceRowIndex)
End Sub

See Also

GetListSourceRowCellValue

CustomColumnDisplayTextEventArgs Class

CustomColumnDisplayTextEventArgs Members

DevExpress.XtraGrid.Views.Base Namespace