分为连接数据源和非数据源两种
非连接数据源
dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].HeaderText = "ID号";
dataGridView1.Columns[1].HeaderText = "时间";
dataGridView1.Columns[2].HeaderText = "心跳值";
DataGridViewRow row = new DataGridViewRow();
//row.Cells["ID号"].Value = "1";
;
row.CreateCells(dataGridView1);
row.Cells[0].Value = "1";
row.Cells[1].Value = "1";
row.Cells[2].Value = "60";
dataGirdView1.Rows.Insert(0,row);
dataGridView1.Rows.Add(row);
连接数据源
DataTable dt = new DataTable();
dt.Columns.Add("a");
dt.Columns.Add("b");
DataRow dr = dt.NewRow();
dr["a"] = "1";
dr["b"] = "2";
dt.Rows.Add(dr);
dr = dt.NewRow();
dataGridView1.DataSource = dt;