DevExpress GridControl line numbers

Artem Makarov picture Artem Makarov · Jul 24, 2012 · Viewed 10.4k times · Source

How to make column with row number? Solutions that works with default WPF dataGrid don't work with DevExpress...

Answer

Stig picture Stig · Jul 24, 2012

You need to add a unboundcolumn to your gridview, you can do this from the designer or from code.

var col = gridView1.Columns.Add();
col.FieldName = "counter";
col.Visible = true;
col.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
gridView1.CustomUnboundColumnData += gridView1_CustomUnboundColumnData;

void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
    if (e.IsGetData)
        e.Value = e.ListSourceRowIndex+1;
}