views:

460

answers:

2

I'm making a Windows Forms application which has a standard DataGridView in it. The DataGridView has several DataGridViewComboBoxColumns in it. And they are a pain to work with. To get one of them to open up (as in, drop down the list), you have to click the cell at least 3 (!!!) times. Seems that the first click ends the editing of the previous cell; The second click activates the cell; and only the third click gets sent to the combobox itself. User interface nightmare, especially when you have to enter a lot of data through these comboboxes.

Is there any workaround?

Added: I just tried it in a blank solution. Just a single form with a single datagridview. The same issue. My colleagues are having the same problem, so I can't be the only one with this. Is there no standard workaround?

+1  A: 

I ran into the same issue with a DataGridView of mine. I solved the problem by changing the selected cell before the DataGridView handles the click itself:

// Subscribe to DataGridView.MouseDown when convenient
this.dataGridView.MouseDown += this.HandleDataGridViewMouseDown;

private void HandleDataGridViewMouseDown(object sender, MouseEventArgs e)
{
    // See where the click is occurring
    DataGridView.HitTestInfo info = this.dataGridView.HitTest(e.X, e.Y);

    if (info.Type == DataGridViewHitTestType.Cell)
    {
        switch (info.ColumnIndex)
        {
            // Add and remove case statements as necessary depending on
            // which columns have ComboBoxes in them.

            case 1: // Column index 1
            case 2: // Column index 2
                this.dataGridView.CurrentCell =
                    this.dataGridView.Rows[info.RowIndex].Cells[info.ColumnIndex];
                break;
            default:
                break;
        }
    }
}
Zach Johnson
A: 

i've had the same problem in one of my own projects.

i'm not sure of all the ramifications of this but i handled this issue by sending F4 when the combobox is entered. It works, but i'm hoping it doesnt blow something up down the line.

Ex:

'This call opens up the ComboBox dropdown immediately instead of having to click into it three times to open the stupid thing
SendKeys.Send("{F4}")

i feel your frustration as you can see from the comment ;)

Jugglingnutcase