wpf DevExpress GridControl 行号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11625344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 04:41:52  来源:igfitidea点击:

DevExpress GridControl line numbers

c#wpfdevexpressgridcontrol

提问by Artem Makarov

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

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

回答by Stig

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

您需要向 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;
}

回答by Ahmad Elkhatib

set the column caption to "#" then add this event to the gridView1

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

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