如何在datagridview里面加一列用于显示行数
rt
------解决方案--------------------Label lblNumber = (Label)e.Row.FindControl( "lblNumber ");
int i = e.Row.RowIndex + 1;
lblNumber.Text = i.ToString();
------解决方案--------------------this.dataGridView1.Columns[0].Name = "序号 ";
for (int i = 1; i < this.dataGridView1.Rows.Count; i++)
{
this.dataGridView1.Rows[i-1].Cells[0].Value = i;
}
------解决方案--------------------你的DataGridView是绑定的那个数据缘 ,比如与DataTable1进行了绑定,增加一个DataTable列,再在DataGridView中增加一个对应列就可以显示了
------解决方案--------------------private void dataGridView1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
int row = 0;
int yDelta = dataGridView1.GetCellDisplayRectangle(row, 0, false).Height + 1;
int y = dataGridView1.GetCellDisplayRectangle(row, 0, false).Top + 2;
CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGridView1.DataSource, dataGridView1.DataMember];
while (y < dataGridView1.Height - yDelta && row < cm.Count)
{
string text = string.Format( "{0} ", row);
e.Graphics.DrawString(text, dataGridView1.Font, new SolidBrush(Color.Black), 12, y);
y += yDelta;
row++;
}
}