2012-07-24 151 views

回答

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

非常感謝! – 2012-07-24 23:31:09

0

設置列標題爲 「#」 那麼這個事件添加到gridView1

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