DevExpress GridControl行号

时间:2012-07-24 06:31:54

标签: c# wpf devexpress gridcontrol

如何使用行号创建列?适用于默认WPF dataGrid的解决方案不适用于DevExpress ...

2 个答案:

答案 0 :(得分:5)

您需要向gridview添加未绑定列,您可以从设计人员或代码中执行此操作。

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;
}

答案 1 :(得分:0)

将列标题设置为"#" 然后将此事件添加到gridView1

    private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
    {
        if (e.Column.Caption == "#")
        {
            e.DisplayText = (e.RowHandle + 1).ToString();
        }
    }