datagridview添加行的几种方式

1、数据绑定

    dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = customersDataSet;

这样就会自动产生对应数据的行数据了。如果不自动产生列,则需手动添加列,把列的数据源属性名(DataPropertyName)设置为对应数据类的属性名。

 

2、手动添加

       songsDataGridView.ColumnCount = 5;
....
songsDataGridView.Columns[0].Name = "Release Date";
....

string[] row0 = { "11/22/1968", "29", "Revolution 9",
"Beatles", "The Beatles [White Album]" };
songsDataGridView.Rows.Add(row0);

 另外,访问行单元格的方式可以这样

this.dataGridView1.Rows[1].Cells[0].Value = "new value";
//或者,等价的
this.dataGridView1[0, 1].Value = "new value";




posted @ 2012-01-11 22:05  果壳中的宇宙  阅读(3576)  评论(0编辑  收藏  举报