【问题标题】:DevExpress GridControl line numbersDevExpress GridControl 行号
【发布时间】:2012-07-24 06:31:53
【问题描述】:

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

【问题讨论】:

    标签: c# wpf devexpress gridcontrol


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多