Discussion:
Adding Context menus to DataGridView column headers
(too old to reply)
Nigel V Thomas
2009-01-16 08:48:00 UTC
Permalink
Good day.

Does anyone know how to add a context menu to a datagrid view control's
column header?

I'm familiar with Context menus and their .show method - I use them
extensively in my app.

I can add a context menu to the DGV column header but it appears relative to
the first column - I'm trying to get the menu to appear over each column as
clicked

Can't find a solution - I suspect there isn't one as the column is not an
object and the CM must be attached to an object

Nigel
Boluwade Kujero
2010-11-21 10:04:03 UTC
Permalink
You have to do it programmatically.

Create and define the ContextMenuStrip and menuitems in design view first. Now select ColumnHeaderMouseClick Event of the DataGridView control and write code to call the ContextMenuStrip after testing the event was raised by the mouse's right button.

For example:

If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.location)
Post by Nigel V Thomas
Good day.
Does anyone know how to add a context menu to a datagrid view control's
column header?
I'm familiar with Context menus and their .show method - I use them
extensively in my app.
I can add a context menu to the DGV column header but it appears relative to
the first column - I'm trying to get the menu to appear over each column as
clicked
Can't find a solution - I suspect there isn't one as the column is not an
object and the CM must be attached to an object
Nigel
Submitted via EggHeadCafe
Client-server autodiscovery in C# and UDP Sockets
http://www.eggheadcafe.com/tutorials/aspnet/9da74d3d-7415-4dfe-984e-2a5db900bdb2/clientserver-autodiscovery-in-c-and-udp-sockets.aspx
Boluwade Kujero
2010-11-21 10:15:02 UTC
Permalink
You have to create the ContextMenuStrip at Design time and call it at run-time under the ColumnHeaderMouseClick event of the DataGridView control. Remember to test for the right button.

e.g:

If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.Location)
Post by Nigel V Thomas
Good day.
Does anyone know how to add a context menu to a datagrid view control's
column header?
I'm familiar with Context menus and their .show method - I use them
extensively in my app.
I can add a context menu to the DGV column header but it appears relative to
the first column - I'm trying to get the menu to appear over each column as
clicked
Can't find a solution - I suspect there isn't one as the column is not an
object and the CM must be attached to an object
Nigel
Post by Boluwade Kujero
You have to do it programmatically.
Create and define the ContextMenuStrip and menuitems in design view first. Now select ColumnHeaderMouseClick Event of the DataGridView control and write code to call the ContextMenuStrip after testing the event was raised by the mouse's right button.
If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.location)
Submitted via EggHeadCafe
Merging SharePoint List Data into Word Documents
http://www.eggheadcafe.com/tutorials/aspnet/6054abc5-c5fb-4e86-a352-afd0e8c4a7c6/merging-sharepoint-list-data-into-word-documents.aspx
Boluwade Kujero
2010-11-21 10:16:00 UTC
Permalink
You have to create the ContextMenuStrip at Design time and call it at run-time under the ColumnHeaderMouseClick event of the DataGridView control. Remember to test for the right button.

e.g:

If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.Location)
Post by Nigel V Thomas
Good day.
Does anyone know how to add a context menu to a datagrid view control's
column header?
I'm familiar with Context menus and their .show method - I use them
extensively in my app.
I can add a context menu to the DGV column header but it appears relative to
the first column - I'm trying to get the menu to appear over each column as
clicked
Can't find a solution - I suspect there isn't one as the column is not an
object and the CM must be attached to an object
Nigel
Post by Boluwade Kujero
You have to do it programmatically.
Create and define the ContextMenuStrip and menuitems in design view first. Now select ColumnHeaderMouseClick Event of the DataGridView control and write code to call the ContextMenuStrip after testing the event was raised by the mouse's right button.
If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.location)
Post by Boluwade Kujero
You have to create the ContextMenuStrip at Design time and call it at run-time under the ColumnHeaderMouseClick event of the DataGridView control. Remember to test for the right button.
If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.Location)
Submitted via EggHeadCafe
Silverlight 4 Coin-Flip Decision Maker based on Mersenne Twister
http://www.eggheadcafe.com/tutorials/aspnet/fabf1bbb-9568-4ff6-859b-7679bc02f13f/silverlight-4-coinflip-decision-maker-based-on-mersenne-twister.aspx
Boluwade Kujero
2010-11-21 10:16:34 UTC
Permalink
You have to create the ContextMenuStrip at Design time and call it at run-time under the ColumnHeaderMouseClick event of the DataGridView control. Remember to test for the right button.

e.g:

If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.Location)
Post by Nigel V Thomas
Good day.
Does anyone know how to add a context menu to a datagrid view control's
column header?
I'm familiar with Context menus and their .show method - I use them
extensively in my app.
I can add a context menu to the DGV column header but it appears relative to
the first column - I'm trying to get the menu to appear over each column as
clicked
Can't find a solution - I suspect there isn't one as the column is not an
object and the CM must be attached to an object
Nigel
Post by Boluwade Kujero
You have to do it programmatically.
Create and define the ContextMenuStrip and menuitems in design view first. Now select ColumnHeaderMouseClick Event of the DataGridView control and write code to call the ContextMenuStrip after testing the event was raised by the mouse's right button.
If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.location)
Post by Boluwade Kujero
You have to create the ContextMenuStrip at Design time and call it at run-time under the ColumnHeaderMouseClick event of the DataGridView control. Remember to test for the right button.
If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.Location)
Post by Boluwade Kujero
You have to create the ContextMenuStrip at Design time and call it at run-time under the ColumnHeaderMouseClick event of the DataGridView control. Remember to test for the right button.
If e.Button = Windows.Forms.MouseButtons.Right Then ContextMenuStrip1.Show(DataGridView1, e.Location)
Submitted via EggHeadCafe
Visual Studio Async CTP Overview
http://www.eggheadcafe.com/tutorials/aspnet/e78665f9-b949-4cc7-a024-654eb3bbad6d/visual-studio-async-ctp-overview.aspx
Loading...