DataGridViewComboBoxColumn - Have to click cell twice to display combo box

前端 未结 1 350
梦如初夏
梦如初夏 2021-01-18 01:05

I am using a DataGridView, created using the designer with a few columns including a DataGridViewComboBoxColumn column.

It is slightly irri

相关标签:
1条回答
  • 2021-01-18 01:31

    You can simply set EditMode property of your DataGridView to EditOnEnter.

    It makes editing more easy. Almost single click, but if you want even when you click on content of combobox show dropdown for your ComboBoxColumn immediately, you can handle CellClick event and then use EditingControl of your grid and cast it to DataGridViewComboBoxEditingControl and makes it to show dropdown.

    private void categoryDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        //You can check for e.ColumnIndex to limit this to your specific column
        var editingControl = this.categoryDataGridView.EditingControl as 
            DataGridViewComboBoxEditingControl;
        if (editingControl != null)
            editingControl.DroppedDown = true;
    }
    

    Be careful when using this trick, you may make drop downs annoying for users when they only want to navigate between cells without editing.

    0 讨论(0)
提交回复
热议问题