Results 1 to 2 of 2

Thread: [RESOLVED] Assign context menu strip to listbox item?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    70

    Resolved [RESOLVED] Assign context menu strip to listbox item?

    How can I assign a context menu strip to a listbox item and not the listbox itself?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Assign context menu strip to listbox item?

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width