DataGridViewComboBoxColumn doesn't open the dropdown on first click

后端 未结 2 831
情深已故
情深已故 2020-12-11 17:38

Before anyone marks this as duplicate, plz note that this is not the same as the questions asked here, here and here.

When you have two or more DataGridViewCom

相关标签:
2条回答
  • 2020-12-11 18:18

    There's nothing wrong with your code. This is the designed behavior for the .NET DataGridView control.

    If you click on the button (the pointing down arrow) on the right side of the drop down control rather then on the text area, the drop down list will show right away - 1 click.

    If you click on the text area of the drop down control, if will get the focus first and then show the drop down list - 2 clicks.

    If at the moment another drop down list is expanded then it would take an extra click to collapse it - that would be 3 clicks.

    There are a couple of workarounds to improve this behavior. Take a look at this MSDN discussion. IMHO these kinds of alterations are not worth it but it's certainly up to you to decide what suits best to your project.

    Best Regards.

    0 讨论(0)
  • 2020-12-11 18:27

    This seems to work for me:

    Set the EditMode to EditProgramatically

    Code the CellMouseClick event:

    private void dgv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        // maybe do a column type check before..!?
        dgv.BeginEdit(false);
        var ec = dgv.EditingControl as DataGridViewComboBoxEditingControl;
        if (ec != null && ec.Width - e.X < SystemInformation.VerticalScrollBarWidth ) 
           ec.DroppedDown = true;
    }
    

    Closing a dropped combobox will still eat one moseclick but that's it how it should be, imo.

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