1、定义一个控件如:commbox
//定义下拉列表框、隐藏控件、在datagridview中添加控件
private ComboBox datacmb=new ComboBox();
datacmb.Visible = false;
this.dataGridView1.Controls.Add(datacmb);
2、添加datagridview的CurrentCellChanged事件
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
try
{
if (this.dataGridView1.CurrentCell.ColumnIndex == 4)
{
Rectangle rec = this.dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, false);
datacmb.Left = rec.Left;
datacmb.Top = rec.Top;
datacmb.Width = rec.Width;
datacmb.Height = rec.Height;
datacmb.Visible = true;
}
else
{
datacmb.Visible = false;
}
}
catch
{
//MessageBox.Show(ex.Message);
}
}