1、DataGridView

DataGridView赋值后 通过RowPostPaint事件绘制行号

 1 private void AddXh() 2  { 3 DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); 4 col.Name = "xh"; 5 col.HeaderText = "序号"; 6 col.FillWeight = 2; 7 dgvEquipment.Columns.Insert(0, col); 8  9 dgvEquipment.RowPostPaint += dgvEquipment_RowPostPaint;10  }11 12 private void dgvEquipment_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)13  {14 foreach (DataGridViewRow row in dgvEquipment.Rows)15  {16 row.Cells["xh"].Value = row.Index + 1;17  }18 }

 

相关文章