先修改DataGrid的TableStyles属性,添加一个DataGridTableStyle,注意它的MappingName="学生表"
sqlConnection1.Open();
sqlDataAdapter1.Fill(dataSet1,"学生表");
dataGrid1.DataMember="学生表";
dataGrid1.DataSource=dataSet1;
DataGridTextBoxColumn dgtb =
(DataGridTextBoxColumn)dataGrid1.TableStyles[0].GridColumnStyles[0];
ComboBox cmbFunctionArea = new ComboBox();
cmbFunctionArea.Items.AddRange(new object[]{"班级一","班级二","班级三"});//另外这里你可以动态从数据库读入得到
cmbFunctionArea.Cursor = Cursors.Arrow;
cmbFunctionArea.DropDownStyle= ComboBoxStyle.DropDownList;
cmbFunctionArea.Dock =do
ckStyle.Fill;
//在选定项发生更改并且提交了该更改后发生
cmbFunctionArea.SelectionChangeCommitted += new EventHandler(cmbFunctionArea_SelectionChangeCommitted);
//把ComboBox添加到DataGridTableStyle的第一列
dgtb.TextBox.Controls.Add(cmbFunctionArea);
//把Combobox上修改的数据提交到当前的网格
private void cmbFunctionArea_SelectionChangeCommitted(object sender, EventArgs e)
{
this.dataGrid1[this.dataGrid1.CurrentCell] = ((ComboBox)sender).SelectedItem.ToString();
}