在C#中,可以通过以下代码来添加列到DataGridView:
dataGridView1.Columns.Add("ColumnName", "Column Header Text");
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.Name = "ColumnName";
column.HeaderText = "Column Header Text";
dataGridView1.Columns.Add(column);
DataGridViewColumn column = new DataGridViewColumn();
column.Name = "ColumnName";
column.HeaderText = "Column Header Text";
column.CellTemplate = new DataGridViewTextBoxCell();
dataGridView1.Columns.Add(column);
注意:在添加列之前,应该确保DataGridView的数据源已经被设置。