views:

409

answers:

2

I have a ComboBox that is a simple drop down style. I wanted to open a new window when the user right clicks on an item in the list, but am having trouble getting it to detect a right click has occurred.

My code:

private void cmbCardList_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right && cmbCardList.SelectedIndex != -1)
    {
        frmViewCard vc = new frmViewCard();
        vc.updateCardDisplay(cmbCardList.SelectedItem);
        vc.Show();
    }
}

If I change e.Button == MouseButtons.Left the whole thing fires off just fine. Any way I can get this working as I intend?

+2  A: 

I'm afraid that will not be posible unless you do some serious hacking. This article will explain.

Quoted for you:

Individual Controls

The following controls do not conform to the standard mouse click event behavior:

Button, CheckBox, ComboBox, and RadioButton controls

  • Left click: Click, MouseClick

  • Right click: No click events raised

  • Left double-click: Click, MouseClick; Click, MouseClick

  • Right double-click: No click events raised

o.k.w
A: 

as said by o.k.w, winforms does not support it, which means you should drop the idea. the fact that winforms doesn't support it, is a smashing prof that it isn't winforms-intuitive. i don't say the conventions of winforms are good, but you must stick to them. i hate software that use a lot of weird events to interact with the user.. i'm sure there is a much simpler way to do what you want.

Itay
@Italy: yea yea, agree totally.
o.k.w