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. DataGridView and ContextMenuStrip

DataGridView and ContextMenuStrip

Scheduled Pinned Locked Moved C#
cssquestion
3 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.
  • P Offline
    P Offline
    paas
    wrote on last edited by
    #1

    I have a DataGridView with an assigned ContextMenuStrip. When I right click on any cell in the grid that is read only, the contextmenu that I expect to see is displayed. However, when I right-click on a non-read only cell that is a DataGridViewTextBoxColumn, I get an unexpected context menu popup with "Cut, Copy, Paste, etc." built-in commands. Clearly this context menu popup is built-in to the DataGridView, but I see no event that would allow me to capture and cancel it from popping up, so I can override it with my preferred context menu. Does anyone know of a way I can prevent this built-in context menu from displaying when right clicking on a DataGridViewTextBoxColumn? Thank you...

    D 1 Reply Last reply
    0
    • P paas

      I have a DataGridView with an assigned ContextMenuStrip. When I right click on any cell in the grid that is read only, the contextmenu that I expect to see is displayed. However, when I right-click on a non-read only cell that is a DataGridViewTextBoxColumn, I get an unexpected context menu popup with "Cut, Copy, Paste, etc." built-in commands. Clearly this context menu popup is built-in to the DataGridView, but I see no event that would allow me to capture and cancel it from popping up, so I can override it with my preferred context menu. Does anyone know of a way I can prevent this built-in context menu from displaying when right clicking on a DataGridViewTextBoxColumn? Thank you...

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      You can probably filter out the message sent when the user rightclicks on DataGridViewColumn. This can be done using PreFilterMessage method of IMessageFilter interface. And then you call show your own contextmenu. Dont know if any simple way exists for this.

      "If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry

      P 1 Reply Last reply
      0
      • D dan sh

        You can probably filter out the message sent when the user rightclicks on DataGridViewColumn. This can be done using PreFilterMessage method of IMessageFilter interface. And then you call show your own contextmenu. Dont know if any simple way exists for this.

        "If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry

        P Offline
        P Offline
        paas
        wrote on last edited by
        #3

        Thanks for the suggestion.

        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