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. ListViews and Context Menus..,

ListViews and Context Menus..,

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 1 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.
  • S Offline
    S Offline
    Shy Agam
    wrote on last edited by
    #1

    Hello experts, I'm trying to have a certain context menu popup when right clicking a ListView's headers, and another context menu popup when right clicking inside of the ListView. Problem is I can't find a way to monitor right clicks on the headers. The ColumnClick event only gets fired when left clicking, and the MouseUp, MouseDown, MouseClick, etc. events are only fired when the mouse is bellow the headers (inside of the ListView). Any suggestions? Thanks in advance, Shy.

    S 1 Reply Last reply
    0
    • S Shy Agam

      Hello experts, I'm trying to have a certain context menu popup when right clicking a ListView's headers, and another context menu popup when right clicking inside of the ListView. Problem is I can't find a way to monitor right clicks on the headers. The ColumnClick event only gets fired when left clicking, and the MouseUp, MouseDown, MouseClick, etc. events are only fired when the mouse is bellow the headers (inside of the ListView). Any suggestions? Thanks in advance, Shy.

      S Offline
      S Offline
      Shy Agam
      wrote on last edited by
      #2

      I've developed a simple workaround... Here it is in case someone finds this post in the future... The ContextMenuStrip property of the ListView is initially set to hold the context menu used when clicking the headers. Assuming that the ListView is called "list", the context menu for the headers is called "ctxtHeaders", and the context menu for the body of the list is called "ctxtBody", here is the implementation:

      private void list_MouseDown(object sender, MouseEventArgs e)
      {
          if (e.Button == MouseButtons.Right)
              list.ContextMenuStrip = ctxtBody;
      }
      
      private void ctxtBody_Closing(object sender, ToolStripDropDownClosingEventArgs e)
      {
          list.ContextMenuStrip = ctxtHeaders;
      }
      

      The code is settings the list's context menu to the body's context menu every time it is about to be shown (i.e. when the right mouse botton is clicked). Then, when the context menu is closed, the list's context menu is set to the headers context menu.

      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