DataGridViewComboBox: Displaying drop down list on Mouse click

G

Guest

Hi!
I having two DataGridViewComboBox columns in a datagridview. I am trying to
display the drop-down list when the user clicks in the cell or the drop-down
arrow (I am not sure if either is possible).
Does anyone know how I can do this?

Thanks for your time.
Regards,
Raj
 
G

Guest

Raj Kumar said:
Hi!
I having two DataGridViewComboBox columns in a datagridview. I am trying to
display the drop-down list when the user clicks in the cell or the drop-down
arrow (I am not sure if either is possible).
Does anyone know how I can do this?

Thanks for your time.
Regards,
Raj

Hi,

You can do it by override the onCellClick on the DataGridView and then call
BeginEdit.
This will get the DateGridview to load the edit control for the selected cell.
Then you can get the current EditControl from the DataGridView control and
then you can set the DroppedDown property to true. Of cause only if the
column is a DataGridViewComboboxColumn so check for that that first.
Example:

private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "YourColumnName")
{
dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
dataGridView1.BeginEdit(true);
DataGridViewComboBoxEditingControl comboboxEdit =

(DataGridViewComboBoxEditingControl)dataGridView1.EditingControl;
comboboxEdit.DroppedDown = true;
}
}

Regards
Rasmus
 
G

Guest

Sorry for responding so late. I had given up on getting a response back.

Thanks for the code snippet. I may have to extend it or make it generic so
that this behavior is available with keyboard navigation as our application
users tend to use the keyboard quite more than the mouse.

Regards,
Raj

Rasmus Knudsen said:
Raj Kumar said:
Hi!
I having two DataGridViewComboBox columns in a datagridview. I am trying to
display the drop-down list when the user clicks in the cell or the drop-down
arrow (I am not sure if either is possible).
Does anyone know how I can do this?

Thanks for your time.
Regards,
Raj

Hi,

You can do it by override the onCellClick on the DataGridView and then call
BeginEdit.
This will get the DateGridview to load the edit control for the selected cell.
Then you can get the current EditControl from the DataGridView control and
then you can set the DroppedDown property to true. Of cause only if the
column is a DataGridViewComboboxColumn so check for that that first.
Example:

private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "YourColumnName")
{
dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
dataGridView1.BeginEdit(true);
DataGridViewComboBoxEditingControl comboboxEdit =

(DataGridViewComboBoxEditingControl)dataGridView1.EditingControl;
comboboxEdit.DroppedDown = true;
}
}

Regards
Rasmus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top