ColumnView.GetDataSourceRowIndex(Int32) Method

Returns the index of the data source record that corresponds to the specified row handle.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

public int GetDataSourceRowIndex(
    int rowHandle
)
Public Function GetDataSourceRowIndex(
    rowHandle As Integer
) As Integer

Parameters

Name Type Description
rowHandle Int32

An integer value representing the row handle.

Returns

Type Description
Int32

The zero-based index of the data record to which the specified row handle corresponds.

Remarks

See the Accessing Rows in Code. Row Handles section in the Rows topic for information on row handles.

NOTE

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

Example

The following example handles the GridView.CustomDrawRowIndicator event to display data source row indexes in the Row Indicator Panel.

using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();

        GridControl gridControl1 = new GridControl { Parent = this, Dock = DockStyle.Fill };
        GridView gridView1 = new GridView();
        gridControl1.MainView = gridView1;
        gridView1.OptionsBehavior.Editable = false;

        Random r = new Random();
        List<MyObject> dataSource = new List<MyObject>();
        for (int i = 0; i < 5; i++) 
            dataSource.Add(new MyObject { Id = r.Next(0, 100), Name = string.Format("Name {0}", i) });
        gridControl1.DataSource = dataSource;

        gridView1.Columns["Id"].SortOrder = DevExpress.Data.ColumnSortOrder.Descending;
        gridView1.CustomDrawRowIndicator += gridView_CustomDrawRowIndicator;
        gridView1.IndicatorWidth = 30;
    }

    void gridView_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) {
        if (!e.Info.IsRowIndicator) return;
        GridView view = sender as GridView;
        int dataSourceRowIndex = view.GetDataSourceRowIndex(e.RowHandle);
        e.Info.DisplayText = dataSourceRowIndex.ToString();
    }

    public class MyObject {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}
See Also