Context Menu on ListBox

  • Thread starter Thread starter Marcus Robinson
  • Start date Start date
M

Marcus Robinson

I need to get a context menu to appear on a listbox to give options for the
selected item. At present the menu appears if you click in any area on the
listbox control, is it possible to have it only appear when the clicked
position is over a list item.

I can get the clicked point, but how can I discover which item is under the
point clicked?

Many thanks,

Marcus Robinson

MR ICT Ltd - http://www.mrict.co.uk
 
Hi Marcus,

I created added a listbox called listbox1 and a context menu called
contextmenu1
i added 5 items in the listbox
i added 1 menuitem in the context menu.

Please see the implementation code:

private void menuItem1_Click(object sender, EventArgs e)
{
MessageBox.Show(listBox1.SelectedItem.ToString());
}

private void Form1_Load(object sender, EventArgs e)
{
listBox1.SelectedValueChanged +=new
EventHandler(listBox1_SelectedValueChanged);
}

void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
contextMenu1.Show(listBox1,new Point(0,0));
}

Thanks,
Russ Du Preez
http://www.cats.co.za
Ultra Rugged, Ultra Reliable Handheld devices
 
Back
Top