DataGridViewComboBoxColumn单击下拉功能

1.设置DataGridView控件的EditMode属性为EditOnEnter

如:DataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter

2.添加DataGridView的CellClick事件,逻辑如下:

private void dgvColumnMap_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex >= 0 && e.RowIndex >= 0 && dgvColumnMap[e.ColumnIndex, e.RowIndex] != null && !dgvColumnMap[e.ColumnIndex, e.RowIndex].ReadOnly)
            {
                DataGridViewComboBoxColumn comboBoxColumn = dgvColumnMap.Columns[e.ColumnIndex] as DataGridViewComboBoxColumn;
                if (comboBoxColumn != null)
                {
                    dgvColumnMap.BeginEdit(true);
                    DataGridViewComboBoxEditingControl comboBoxEditingControl = dgvColumnMap.EditingControl as DataGridViewComboBoxEditingControl;
                    if (comboBoxEditingControl != null)
                    {
                        comboBoxEditingControl.DroppedDown = true;
                    }
                }
            }
        }

你可能感兴趣的:(datagridview)