Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Question about ContextMenu on ListView? [modified]

Question about ContextMenu on ListView? [modified]

Scheduled Pinned Locked Moved C#
questionhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Khoramdin
    wrote on last edited by
    #1

    Hello, I have a listview control with bunch of entries. When the user right-clicks on the item, I want a context menu to come up. So I created a ContextMenu instance and assigned it to ListView.ContextMenu property. The problem is that the context menu comes up regardless of whether I right-click on the item or the empty space or the column header. I want it only to come up when the user right-clicks on an item. How can I control the ContextMenu better? Thank you very much and have a great day. Khoramdin

    J 1 Reply Last reply
    0
    • K Khoramdin

      Hello, I have a listview control with bunch of entries. When the user right-clicks on the item, I want a context menu to come up. So I created a ContextMenu instance and assigned it to ListView.ContextMenu property. The problem is that the context menu comes up regardless of whether I right-click on the item or the empty space or the column header. I want it only to come up when the user right-clicks on an item. How can I control the ContextMenu better? Thank you very much and have a great day. Khoramdin

      J Offline
      J Offline
      Jupiter9
      wrote on last edited by
      #2

      On the mousedown event for the listview place the following code: if (ListView1.GetItemAt(new Point(e.X, e.Y)) != null) ListView1.ContextMenu = yourContextMenu; else ListView1.ContextMenu = null;

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups