用原始datagridview的列名赋值的时候找不到列名,用索引就可以,不知道是怎么回事
DataGridViewRow dr = new DataGridViewRow();
dr.CreateCells(this.dataGridView1);
for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
{
dr.Cells[this.dataGridView1.Columns[i].Index].Value = this.dataGridView1.Columns[i].Name;
}
this.dataGridView1.Rows.Add(dr);
如果把红字换成this.dataGridView1.Columns[i].Name就报找不到这个列名。
allSize = allSize - 100;
if (allSize < 200) columnSize = allSize + 27;//列宽初始化调整
DataGridViewColumn dataGridViewColumn = new DataGridViewColumn();
DataGridViewCell dataGridViewCell = new DataGridViewTextBoxCell();
dataGridViewColumn.CellTemplate = dataGridViewCell;//设置单元格文本格式//异常
dataGridViewColumn.Width = columnSize;//单元格大小
dataGridViewColumn.HeaderText = str;
dataGridView1.Columns.Add(dataGridViewColumn);
}