在Datagridview 控制元件DataGridViewComboBoxColumn怎麼點兩次才下拉下來

衣舞晨風發表於2015-06-30

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的命名

本文參考網路文章,但很多文章都寫自己是原創,我就隨便找一個作為原文地址吧

點選開啟連結

相關文章