EditMode设为EditOnEnter
不过每次都要点击下来框的小三角才可以
添加如下函数,可以实现点击一次下拉:
private void dgvState_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 && e.RowIndex >= 0 && dgvState[e.ColumnIndex, e.RowIndex] != null && !dgvState[e.ColumnIndex, e.RowIndex].ReadOnly)
{
DataGridViewComboBoxColumn comboBoxColumn = dgvState.Columns[e.ColumnIndex] as DataGridViewComboBoxColumn;
if (comboBoxColumn != null)
{
this.dgvState.CurrentCell = dgvState[e.ColumnIndex, e.RowIndex];
dgvState.BeginEdit(true);
DataGridViewComboBoxEditingControl comboBoxEditingControl = dgvState.EditingControl as DataGridViewComboBoxEditingControl;
if (comboBoxEditingControl != null)
{
comboBoxEditingControl.DroppedDown = true;
}
}
}
}
dgvState为datagridview的命名
原文:https://blog.csdn.net/jiankunking/article/details/46696057