//绑定数据源
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
{
...获得DataGridView及ComboBox数据源
}
datagridview1.DataSource = dt1;
//创建要更改的列对象
DataGridViewComboBoxColumn dgvcbc = new DataGridViewComboBoxColumn();
dgvcbc.DataSource = dt2;
dgvcbc.DisplayMember = "要显示的字段名";
dgvcbc.ValueMember = "值字段名";
dgvcbc.HeaderText = "列头";
dgvcbc.ReadOnly = true/false ;是否编辑用
dgvcbc.DisplayStyle = DataGridViewComboBoxColumnDisplayStlay.ComboBox; 可选
//可有可无,在未知索引的情况下
foreach(DataGridViewColumn var in datagridview1.Columns)
{
...找到你要更改的列的索引 index
}
//在要更改的列前面插入新列
datagridview1.Columns.insert(index,dgvcbc);
//为新列更改值
foreach(DataGridViewRow var in datagridview1.Rows)
{//自己看着办,选中值有很多种方法
dgvcbc.SelectedValue = var.Cells[index+1].Value.toString();
}
//将要替换的列删除,这样新添加的列顺理成章的替换了原来的列
datagridview1.Removeat(index+1);