Problem : You have added ContextMenu
to the DataGridView
after RightClick
event. so ContextMenu
willbe added to your DataGridView
after the first RightClick
hence user can see the attached ContextMenu
from the further RightClick
events.
Solution : you need to add the ContextMenu
before right clicking on the DataGridView
so that it will be appeared for each RightClick
event.
Note : if ContextMenu
is assigned to any control , it willbe displayed on rightclick
by default, means you do not need to add it for each RightClick
event on the control explicitly.
Try This: in Form Load
Event
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
ContextMenuStrip Menu = new ContextMenuStrip();
ToolStripMenuItem MenuOpenPO = new ToolStripMenuItem("Delete it");
MenuOpenPO.Click += new EventHandler(MenuOpenPO_Click);
Menu.Items.AddRange(new ToolStripItem[] { MenuOpenPO });
dataGridView1.ContextMenuStrip = Menu; //Assign to dataGridView1
}