DataGridViewComboBoxCell cbcell1 = new DataGridViewComboBoxCell();
cbcell1.Items.Add("无所谓");
cbcell1.Items.Add("上午多");
cbcell1.Items.Add("下午多");
cbcell1.Items.Add("一样多");
cbcell1.AutoComplete = true;
cbcell1.DisplayStyleForCurrentCellOnly = true;
DataGridViewColumn column6 = new DataGridViewColumn(cbcell1);
column6.HeaderText = "一周课时分配";
column6.DataPropertyName = "AllotNature";
column6.ReadOnly = false;
this.dataGridView1.Columns.Add(column6);
this.dataGridView1.Rows.Add();
首先确定单元格类型,然后把它添加到列里面,最后把它添加到行里面!
datagridview,那就是winform?添加新列?你是在数据库添加还是手动添加像checkbox之类的列?
DataTable t=datagridview.DataSource;
t.Columns.add(new DataColumn());
datagridview.DataSource=t;