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?
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With