Open contextmenustrip when right-clicking on the items displayed in the listbox

Asked

Viewed 195 times

0

I tried this way:

private void listBox1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
            contextMenuStrip1.Show(listBox1.PointToScreen(new Point(e.X, e.Y)));
        }
    }

But I need it to be the items on the listbox not the entire listbox, how can I do it?

  • You are trying to prevent the menu from being shown when you click on an area that has no items?

  • Yes that’s right.

  • Why don’t you test the SelectedIndex of ListBox ? With this you can know if you have a selected one and open the menu in relation to what is selected.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.