// creating Context menu for data grid.
ToolStripMenuItem mnuStart = new ToolStripMenuItem("Start");
ToolStripMenuItem mnuStartAll = new ToolStripMenuItem("StartAll");
ToolStripMenuItem mnuPause = new ToolStripMenuItem("Pause");
ToolStripMenuItem mnuDelete = new ToolStripMenuItem("Delete");
mnuStart.Click += new EventHandler(mnuStart_Click); // creating the event handeler for the context menu.
mnuStartAll.Click += new EventHandler(mnuStartAll_Click);
mnuPause.Click += new EventHandler(mnuPause_Click);
mnuDelete.Click += new EventHandler(mnuDelete_Click);
//Add to main context menu
mnu.Items.AddRange(new ToolStripItem[] { mnuStart, mnuStartAll, mnuStartAll, mnuPause, mnuDelete });
and for assigning it for the Mouse Right Click please use the following code..
private void dgFile_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (dgFile.Rows.Count == 0)
{
dgFile.ContextMenuStrip = null;
}
else
{
dgFile.ContextMenuStrip = mnu;
}
}
}
ThanksAnil Kumar PandeySystem ArchitectGreen Point Technology (India) Ltd.Mumbai, MaharshtraINDIA
No comments:
Post a Comment