動態添加行
//首先 聲明一個 DataGridViewRow 對象 (即要添加的行)
DataGridViewRow dr = new DataGridViewRow();
//設置要添加行的列
DataGridViewCheckBoxCell check=new DataGridViewCheckBoxCell();
DataGridViewTextBoxCell text=new DataGridViewTextBoxCell();
dr.Cells.Add(check);
dr.Cells.Add(text);
//設置列的值
dr.Cells[1].Value = "aaaa";
//將聲明的行添加到dataGridView1 中
dataGridView1.Rows.Add(dr);
/////////////////////////////////////////////////////////////////////////////////
//添加列
DataGridViewColumn dc = new DataGridViewColumn();
dc.DataPropertyName = "FID";
dc.Visible = false;
dc.SortMode = DataGridViewColumnSortMode.NotSortable;
dc.HeaderText = "唯一ID";
dc.CellTemplate = null;
this.dgv_StockList.Columns.Add(dc);