override datagrid cell context menu?

  • Thread starter Thread starter Michael Wortman
  • Start date Start date
M

Michael Wortman

My datagrid context menu does not display if the cursor is
within a cell or the cell text is selected... instead the
standard cut/copy/paste menu is displayed. how do I get
my menu to always show up?

thanks a bunch
mike
 
Hello Michael,

To popup your ContextMenu for the whole DataGrid control, you need to
assign the context menu to each control in your DataGrid control. You may
do this in the ControlAdded event, this is a sample code:

private void InitializeComponent()
{
this.dataGrid1.ContextMenu = this.contextMenu1;
this.dataGrid1.ControlAdded += new
System.Windows.Forms.ControlEventHandler(this.dataGrid1_ControlAdded);
}

private void dataGrid1_ControlAdded(object sender, ControlEventArgs e)
{
e.Control.ContextMenu = contextMenu1;
}

I hope this helps you.

Best regards,

Lion Shi [MSFT]
MCSE, MCSD
Microsoft Support Engineer
Get Secure! ¨C www.microsoft.com/security

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2003 Microsoft Corporation. All rights
reserved.
--------------------
| Content-Class: urn:content-classes:message
| From: "Michael Wortman" <[email protected]>
| Sender: "Michael Wortman" <[email protected]>
| Subject: override datagrid cell context menu?
| Date: Fri, 1 Aug 2003 11:08:48 -0700
| Lines: 7
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNYV/TZEWg6e9LgSQGL7Y9Wx7i0uA==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:49428
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| My datagrid context menu does not display if the cursor is
| within a cell or the cell text is selected... instead the
| standard cut/copy/paste menu is displayed. how do I get
| my menu to always show up?
|
| thanks a bunch
| mike
|
 
Hello Michael,

Glad to hear it helps :)

Best regards,

Lion Shi [MSFT]
MCSE, MCSD
Microsoft Support Engineer
Get Secure! ¨C www.microsoft.com/security

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2003 Microsoft Corporation. All rights
reserved.
--------------------
| Content-Class: urn:content-classes:message
| From: "freshg" <[email protected]>
| Sender: "freshg" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: override datagrid cell context menu?
| Date: Wed, 6 Aug 2003 11:41:13 -0700
| Lines: 81
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: quoted-printable
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNcSk/p6Yl5/fE3Sa2/T/O8Jcv1uw==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:49722
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| awesome. that worked perfectly. accomplished exactly
| what I needed.
| Thanks a million
| >-----Original Message-----
| >Hello Michael,
| >
| >To popup your ContextMenu for the whole DataGrid control,
| you need to
| >assign the context menu to each control in your DataGrid
| control. You may
| >do this in the ControlAdded event, this is a sample code:
| >
| >private void InitializeComponent()
| >{
| > this.dataGrid1.ContextMenu = this.contextMenu1;
| > this.dataGrid1.ControlAdded += new
| >System.Windows.Forms.ControlEventHandler
| (this.dataGrid1_ControlAdded);
| >}
| >
| >private void dataGrid1_ControlAdded(object sender,
| ControlEventArgs e)
| >{
| > e.Control.ContextMenu = contextMenu1;
| >}
| >
| >I hope this helps you.
| >
| >Best regards,
| >
| >Lion Shi [MSFT]
| >MCSE, MCSD
| >Microsoft Support Engineer
| >Get Secure! ¨C www.microsoft.com/security
| >
| >This posting is provided "AS IS" with no warranties, and
| confers no rights.
| >You assume all risk for your use. 2003 Microsoft
| Corporation. All rights
| >reserved.
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "Michael Wortman" <[email protected]>
| >| Sender: "Michael Wortman" <[email protected]>
| >| Subject: override datagrid cell context menu?
| >| Date: Fri, 1 Aug 2003 11:08:48 -0700
| >| Lines: 7
| >| Message-ID: <[email protected]>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| >| Thread-Index: AcNYV/TZEWg6e9LgSQGL7Y9Wx7i0uA==
| >| Newsgroups:
| microsoft.public.dotnet.framework.windowsforms
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| >microsoft.public.dotnet.framework.windowsforms:49428
| >| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| >| X-Tomcat-NG:
| microsoft.public.dotnet.framework.windowsforms
| >|
| >| My datagrid context menu does not display if the cursor
| is
| >| within a cell or the cell text is selected... instead
| the
| >| standard cut/copy/paste menu is displayed. how do I
| get
| >| my menu to always show up?
| >|
| >| thanks a bunch
| >| mike
| >|
| >
| >.
| >
|
 
Back
Top