views:

2077

answers:

4

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?

+5  A: 

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.

thismat
+1  A: 

I have been able to get close to what you're looking for by setting

DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter

As long as no other cell's dropdown is shown it should display the selected cell's dropdown immediately.

I'll keep thinking and update if anything comes up.

PersistenceOfVision
+2  A: 

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;
}
I'm glad you got it working!
thismat
This was amazingly helpful.
BrianH
A: 

Thanks ThisMat, it's works great

bkris