How can I assign a context menu strip to a listbox item and not the listbox itself?
Printable View
How can I assign a context menu strip to a listbox item and not the listbox itself?
You can't. You can only associate a ContextMenuStrip with a control and the individual items in the ListBox are not controls.
What you would have to do is detect a right-click on the ListBox yourself, determine what item is under the mouse pointer and then call Show on the appropriate ContextMenuStrip.
Towards that end, you would:
1. Handle the MouseClick event.
2. Test for the right mouse button.
3. Call GetItemRectangle method for each item.
4. Test which item contains the location that was clicked.