I was able to activate combo box and drop down it using a single mouse click by setting EditMode property of DataGridView to EditOnEnter
and creating EditingControlShowing event and added code to drop down the combo box in this event. Here is the sample code -
//to get the correct cell get value of row and column indexs of the cell
ColIndex = 1;
RowIndex = 1;
DataGridViewComboBoxCell ComboBoxCell = new DataGridViewComboBoxCell();
ComboBoxCell.Items.AddRange("XYZ", "ABC", "PQR");
ComboBoxCell.Value = "XYZ";
datagridview1[ColIndex, RowIndex] = ComboBoxCell;
From the above code DataGirdCell at the location (1,1) will be converted to a "DataGridViewComboBoxCell" and combo box will be shown in the cell.
It might be possible that to dropdown the combo box multiple mouse clicks are required. To activate combo box on single click following steps are required -
- Set ReadOnly property of the combobox cell to false
- Set EditMode property of DataGridView to EditOnEnter
- Create EditingControlShowing event and add code to drop down the combo box
Here is the sample code to drop down the combo box and activate it on single click -
private void datagridview1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox ctrl = e.Control as ComboBox;
ctrl.Enter -= new EventHandler(ctrl_Enter);
ctrl.Enter += new EventHandler(ctrl_Enter);
}
void ctrl_Enter(object sender, EventArgs e)
{
(sender as ComboBox).DroppedDown = true;
}
For more detail please check -
http://newapputil.blogspot.in/2015/08/add-combo-box-in-cell-of-datagridview.html