C# 如何手動添加DataGridViewRow到DataGridView
SortableBindingList<ImportUseableInfo> models = item.GetUseableBargainByCIQPN(ciqpn);//獲取數據集 //this.dataGridView1.DataSource = item.GetUseableBargainByCIQPN(ciqpn); foreach (ImportUseableInfo model in models) { DataGridViewRow dr = new DataGridViewRow(); dr.Cells["BargainNO"].Value = model.BargainNO; dr.Cells["SeqID"].Value = model.SeqID; dr.Cells["CIQPN"].Value = model.CIQPN; dr.Cells["CIQCode"].Value = model.CIQCode; dr.Tag=model.UseQty; this.dataGridView1.Rows.Add(dr); }
foreach (ImportUseableInfo model in models) { DataGridViewRow dr = new DataGridViewRow();foreach(DataGridViewCell c in dataGridView1.Columns){dr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);//给行添加单元格} dr.Cells["BargainNO"].Value = model.BargainNO; dr.Cells["SeqID"].Value = model.SeqID; dr.Cells["CIQPN"].Value = model.CIQPN; dr.Cells["CIQCode"].Value = model.CIQCode; dr.Tag=model.UseQty; this.dataGridView1.Rows.Add(dr); }