1

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

4

2 回答 2

6

您需要向您的 gridview 添加一个 unboundcolumn,您可以从设计器或代码中执行此操作。

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;
}
于 2012-07-24T08:34:59.340 回答
0

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

    private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
    {
        if (e.Column.Caption == "#")
        {
            e.DisplayText = (e.RowHandle + 1).ToString();
        }
    }
于 2014-10-28T15:01:35.383 回答