导读:
第一:
先在窗体设计时拖一个ComBoBox控件,然后在里面的ITEMS设好你要下拉项,这个不用教了吧...
第二:
在窗体的Load方法中加入:g_DataGridView.Controls.Add(g_ComBoBox);也就是把ComBoBox控件添加到DataGridView控件中
第三:
在DataGridView控件的CurrentCellChanged方法中写如下代码:
DataGridViewCell CurrnetCell =g_View.CurrentCell;if(CurrnetCell !=null&&CurrnetCell.OwningColumn.Name =="列名")
{
Rectangle TmpRect =g_DataGridView.GetCellDisplayRectangle(CurrnetCell.ColumnIndex, CurrnetCell.RowIndex, true);
g_ComBoBox.Text =CurrnetCell.Value.ToString();
g_ComBoBox.Size =TmpRect.Size;
g_ComBoBox.Top =TmpRect.Top;
g_ComBoBox.Left =TmpRect.Left;
g_ComBoBox.Visible =true}else{
g_ComBoBox.Visible =false}
最后在ComBoBox控件的SelectedIndexChanged方法中写:
g_DataGridView.CurrentCell.Value = g_ComBoBox.Text;