1

I am working on project in which I have a datagridview containing normal textbox cells & comboboxcells too, I can catch mouseDoubleClick event in normal textbox cells from datagridview's MouseDoubleClick event handler. But I have no idea about how to fire & catch DataGridViewComboBoxCell.MouseDoubleClick event.

Please, help me how to accomplish it.

techraf
  • 64,883
  • 27
  • 193
  • 198
  • This is not really a good idea. Comboboxes, real or in dgv columns [do not support doubleclicks](https://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.doubleclick%28v=vs.110%29.aspx). So you should not try to make it work here when it won't work in the rest of windows! – TaW Sep 24 '16 at 14:03
  • Ok TaW, if it realy does not support double click, then let me explain what I am trying to do. The datagrid view shows, day number of month (June1, June 2, June3 … June 30) in column headers and customer names in row headers, now if the customer transacts more than once a day, each transaction-Id comes in the form of datagridviewcombobox item. I want, when the transaction-ID is clicked the transaction detail(Cash memo) is shown in another form. Now, if DataGridViewComboBoxCell does not support mouseDouble click, then is there any alternate method to accomplish my requirement?!!? Thank you. :) – Rajib Majumdar Sep 24 '16 at 14:43
  • Is the DGV read-only or can the user edit the content? When a multi-value cell is clicked/doubleclicked shall the new form show all values or only the currently selected one? – TaW Sep 24 '16 at 14:57
  • Yes the entire dgv is read only except the combobox cells( I had to do it to be able to change the selected item of the same.). Actually, initialy I set the datagridview as dgv.ReadOnly = false; now while loading TranxID to each cell, I set them as readonly= true. And if the item found in a datatable for a particular 'date' AND 'Name' set is more than one, I instantiate a dgvComboBoxCell & assign it to the corresponding location of dgv & set it's property as ReadOnly= false;. And answer to your second question: No! New form will show the cashmemo corresponding to existing selection(ID). – Rajib Majumdar Sep 24 '16 at 15:17
  • I tried getting a workaround to work but it just won't work reliably. I suggest you use the right button to open the window. this is ismple an in line with windows ui which brings up context specific menu otherwise.. – TaW Sep 24 '16 at 18:16

1 Answers1

0

ComboBoxes, real or in dgv columns do not support doubleclicks. So you should not try to make it work here when it won't work in the rest of windows!

I suggest using a different user action; clicking with the right button comes to mind. It usually brings up a context-sensitive menu, so it seems a good choice..

I use the HitTest function to find the cell since a ComboBoxColumn can make it hard to determine the cell that was hit..

private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button.HasFlag(MouseButtons.Right))
    {
        DataGridView.HitTestInfo hit = dataGridView1.HitTest(e.X, e.Y);
        DataGridViewCell cell = dataGridView1[hit.ColumnIndex, hit.RowIndex];
        // call some event..
        yourInfoAction(cell.Value);
    }
}
TaW
  • 53,122
  • 8
  • 69
  • 111
  • Very unlucky TaW! My desktop gone :(. Can not check atleast within a couple of days. I will reply after I check it. :) Definitely, your idea is a good one. :) however, what about this https://msdn.microsoft.com/en-us/library/ms171543(v=vs.110).aspx will it be suitable? Anyway, now I can not check it either. :( – Rajib Majumdar Sep 25 '16 at 01:21
  • Interesting link; this is basically the very workaround I was playing with.But our problem is harder because we have to deal with three different controls: the DGV, the combobox closed and the combobox opend and I just can't make it work reliably a few times in a row. (twice works fine but then it just stops until one leaves the cell :-() - I'll try a little more, but I'm not sure.. - Good luck with you machine!!! – TaW Sep 25 '16 at 07:27
  • Thank you! TaW you code is working perfectly. (y). Thank you once again for the geand idea of right click window opening(event firing). Oo yes, what about the click and double click simulation?!! ;) – Rajib Majumdar Sep 26 '16 at 14:27