
首先創建一個DataGridView控件,然后創建列(包括列名的定義),
由於我不是和數據庫進行連接,只是為了輸出好看一點。
刪除所有數據:
while (this.dataGridView1.Rows.Count != 0)
{
this.dataGridView1.Rows.RemoveAt(0);
}
添加一行數據:
index = this.dataGridView1.Rows.Add();//獲取新的一行
this.dataGridView1.Rows[index].Cells[0].Value = “第一列”;
this.dataGridView1.Rows[index].Cells[1].Value = “輸出形式為字符串”;
this.dataGridView1.Rows[index].Cells[2].Value = "第三列";
