Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manually drop down a DataGridViewComboBoxColumn?

I have a DataGridView with one DataGridViewComboBoxColumn in my WinForms application. I need to drop down (open) this DataGridViewComboBoxColumn manually, let's say after a button is clicked.

The reason I need this is I have set SelectionMode to FullRowSelect and I need to click 2-3 times to open the combo box. I want to click on the combobox cell and it should drop down immediately. I want to do this with CellClick event, or is there any other way?

I am searching in Google and VS help, but I haven't found any information yet.

Can anybody help please?

like image 356
user20353 Avatar asked Oct 27 '08 19:10

user20353


2 Answers

I know this can't be the ideal solution but it does create a single click combo box that works within the cell.

   Private Sub cell_Click(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        DataGridView1.BeginEdit(True)
        If DataGridView1.Rows(e.RowIndex).Cells(ddl.Name).Selected = True Then
            DirectCast(DataGridView1.EditingControl, DataGridViewComboBoxEditingControl).DroppedDown = True
        End If
    End Sub

where "ddl" is the combobox cell I added in the gridview.

like image 183
thismat Avatar answered Nov 20 '22 01:11

thismat


Thanks ThisMat, your solution works perfectly.

My code in C#:

private void dataGridViewWeighings_CellClick(object sender, DataGridViewCellEventArgs e) {
    if (e.RowIndex < 0) {
        return;     // Header
    }
    if (e.ColumnIndex != 5) {
        return;     // Filter out other columns
    }

    dataGridViewWeighings.BeginEdit(true);
    ComboBox comboBox = (ComboBox)dataGridViewWeighings.EditingControl;
    comboBox.DroppedDown = true;
}
like image 18
user20353 Avatar answered Nov 20 '22 03:11

user20353