首先要定义DataGridViewComboBoxCell 列
触发事件时要用 把当前的CurrentCell 转换成DataGridViewComboBoxCell
DataGridViewComboBoxCell cell = dataGridView1.CurrentCell as DataGridViewComboBoxCell;
cell.DataSource = codeTableBLL.GetWormStatus(tempValue.Split('|')[0]);
cell.DisplayMember = "StatusName";
cell.ValueMember = "StatusID";
这里有个问题的 就是DataGridViewComboBoxCell 赋默认值的时候 一定要跟绑定的数据元里面的值对应,如果数据库里面没这个值就会报错.
另外 取某一cell值可以用 dataGridView1.Rows[0].Cells[2].Value=((DataTable)cell.DataSource).Rows[0][0].ToString();
如果报错 侧采用另外一种动态绑定combox的方法
使用
直接 使用combox控件.利用combox.SetBounds位置的显示来实现.combox的样式选 DropDownList
Rectangle R = dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
cbxCommon.SetBounds(R.X + dataGridView1.Location.X, R.Y + dataGridView1.Location.Y + 1, R.Width, R.Height);
另外可以参考 http://msdn.microsoft.com/zh-cn/ms404353.aspx 对combox有详细介绍;