How to activate combobox on first click (Datagridview)

后端 未结 6 641
故里飘歌
故里飘歌 2020-12-13 12:48

In winforms, you need to click the combobox twice to properly activate it - the first time to focus it, the second time to actually get the dropdown list.

How do I c

6条回答
  •  眼角桃花
    2020-12-13 13:22

    Set the following on your DataGridView:

    EditMode = EditOnEnter
    

    This is probably the easiest solution and has been the workaround for many users here on SO when this question gets asked.


    EDIT :

    Per here do the following:

    Set the Editmode:

    EditMode = EditOnKeystrokeOrF2
    

    Modify the EditingControlShowing event on the datagridview:

    private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        ComboBox ctl = e.Control as ComboBox;
        ctl.Enter -= new EventHandler(ctl_Enter);
        ctl.Enter += new EventHandler(ctl_Enter);
    
    }
    
    void ctl_Enter(object sender, EventArgs e)
    {
        (sender as ComboBox).DroppedDown = true;
    }
    

    This will get you your desired results. Let me know if that doesn't do it.

提交回复
热议问题