I am having a bit of problem with a contextmenu popup. I have a datagridview that I want a user to be able to right click on a cell and get the contextmenu displayed. The user can multi-select continous or non-continuous cells. Right click and get a context menu. I have read through the stack overflow questions and tried out the suggestions and none have worked for me. The context menu does not display near the selected cell.
I am coding behind the datagridview cellmouse down event and checking for right mouse button. Here is my code:
if (e.Button == MouseButtons.Right)
{
ContextMenu m = new ContextMenu();
MenuItem mi = new MenuItem("Set Online");
mi.Click += setOnlineItemCell_Click;
m.MenuItems.Add(mi);
MenuItem mi2 = new MenuItem("Set Offline");
mi2.Click += setOfflineItemCell_Click;
m.MenuItems.Add(mi2);
m.Show(machineGrid, new Point(e.X, e.Y));
}
I cannot pass just a single parameter to the Show method as it complains it can't find it (even though MSDN says you can).
Any help in getting the contextmenu to display close to the cell would be greatly appreciated.
C#,Visual Studio 2015 Professional, .NET 4.5.2