473,549 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ContextMenu does not work in DataGridView

I cant get a contextmenu to popup in the context of a datagridview. It
pops up in the ListBox, and in the form itself. But not the
DataGridView. How could that be?

here is my code:

using System;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace demo_DataGridVi ew2
{

public partial class Form1 : Form
{
DataGridView mGrid1 = null ;
ContextMenu mContextMenu = null;
ListBox mListBox1 = null;

public Form1()
{
this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
this.Text = "Form1";
this.Width = this.Font.Heigh t * 40;

mContextMenu = new ContextMenu();
mContextMenu.Po pup += contextMenu_Pop up;

mListBox1 = new ListBox();
mListBox1.Paren t = this;
mListBox1.Locat ion = new Point(10, 30);
mListBox1.Heigh t = this.Font.Heigh t * 5;
mListBox1.Width = this.Font.Heigh t * 30;
mListBox1.Items .Add("line 0");
mListBox1.Items .Add("line 1");

mGrid1 = new DataGridView();
mGrid1.Parent = this;
mGrid1.Location = new Point(10, 120);
mGrid1.Height = this.Font.Heigh t * 5;
mGrid1.Width = this.Font.Heigh t * 30;
mGrid1.ColumnCo unt = 3;
mGrid1.AutoGene rateColumns = true;

string[] row1 = new string[3] {"col1", "col2", "col3"} ;
string[] row2 = new string[3] { "col1", "col2", "col3" };
mGrid1.Rows.Add (row1);
mGrid1.Rows.Add (row2);

this.ContextMen u = mContextMenu;
mListBox1.Conte xtMenu = mContextMenu;
mGrid1.ContextM enu = mContextMenu;
}

protected void contextMenu_Pop up(System.Objec t InSender,
System.EventArg s InArgs)
{
mContextMenu.Me nuItems.Clear() ;
if (mContextMenu.S ourceControl == this)
{
mContextMenu.Me nuItems.Add( new MenuItem("form menu item")) ;
}
else if (mContextMenu.S ourceControl == mGrid1)
{
mContextMenu.Me nuItems.Add( new MenuItem("grid menu item")) ;
}
else if (mContextMenu.S ourceControl == mListBox1)
{
mContextMenu.Me nuItems.Add(new MenuItem("ListB ox menu item"));
}
}

} // end class Form1
} // end namespace demo_table

Aug 27 '07 #1
0 1546

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
4553
by: DJ WIce | last post by:
Hi all, I did make a script/css thing to replace the contextmenu on the website with a new one: http://www.djwice.com/contextmenu.html It works nice in MSIE, but on Netscape (and probable other browsers) it stays on the same place (does not "open'' where the mouse is). And the links do not work when you click on them. If anyone has...
0
1652
by: MD | last post by:
I have a ContextMenu that is assigned to 3 RichTextBox's (i.e., if you right-click on any of the 3 RichTextBox's, you get the same ContextMenu). My ContextMenu has 2 items, each of which have their own click event handlers. When I click on any of the options in the ContextMenu, I want to know which RichTextBox the ContextMenu is currently...
1
2025
by: Brian Martel | last post by:
I am trying to create a dynamic flyout submenu off of a contextmenu. I can right click and get the base contextmenu ok. On the Popup event I add MenuItem's to the collection of one of the items so it has a flyout submenu when selected. If I try and add more than 1 item to the submenu it only shows up the first time. This same code works fine...
0
1206
by: Daniel K. | last post by:
I've got a form with a usercontrol and a contextmenu for it. I put everything together in the VS form designer. the codesnipped below is from that dialog. The problem: Before i added the cmObjektTree.Dispose() call in the forms' dispose function, the garbage collector didn't collect my form and everything on / related to it if i opened the...
1
2667
by: chinimimita.hernandez | last post by:
Does anyone know how windows service work with notifyicon and contextmenu? I was able to run the windows service with notifyicon part but when I inserted the contextmenu command it didn't work. When I read the MSDN articles about the windows service it says that if my WS needs to be interactive I need to access the unmanaged windows API. but...
7
1372
by: TryingLikeHeck | last post by:
I have a usercontrol on which I've generated a context menu in designer. The properties of the control lists for ContextMenu (none) The menu shows up in the designer window and I can edit it To assign my menu to the property in New I do ContextMenu = RePopupMenu To show it, on right mouse down I do ContextMenu.Show(Me, New...
11
2647
by: Graham Charles | last post by:
I'm writing a control inheriting from ComboBox, and I'd like to add an entry to the ContextMenu for that combo box. I have no problem if I create an entirely new ContextMenu from scratch, but I'd prefer just to tack my MenuItem on to the existing, built-in ContextMenu (Cut, Copy, Paste, etc.): _RemoveMRUItemMenu = New MenuItem...
6
1810
by: emmajoh | last post by:
Hi I'm trying to disable IE contextmenu (on a right click) as I want to create my own. The problem is that since I've installed the latest version of the google desktop, the script doesn't work. No other script I found on the Internet is working anymore. As you can see below, I've tried to catch every event I'm aware of:...
1
6715
by: Darin | last post by:
I understand microsoft's change from contextmenu to contextmenustrip - the strip looks "prettier". But, since the contextmenu isn't available in the designer, it suer woul dhave been nice when updating a project from VS2003 to VS2005 that it asked if you wanted to change all of the menus. I now have hundreds (if not thousands) of menus...
0
7464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7734
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7979
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7826
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6065
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5385
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5107
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1960
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.