We can create context menu for the Data Grid cell here is the code to create the context menu and to assign the event..
// 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; } } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|