最近工作中用到了动态给DataGridView添加列 并给此列赋值,故记录一下
var col = new DataGridViewColumn(); //要插入列的类型 col.CellTemplate = new DataGridViewTextBoxCell(); col.Name = "colName"; col.HeaderText = "显示名称"; dgvWorkList.Columns.Insert(4, col); //插入列赋值 for (int i = 0; i < dgvWorkList.Rows.Count; i++) { dgvWorkList.Rows[i].Cells["colName"].Value = "value"; }