C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » DataGridView »

Creating Context Menu for Data Grid


Posted Date: 24 Jun 2009    Resource Type: Code Snippets    Category: DataGridView
Author: Anil Kumar PandeyMember Level: Diamond    
Rating: 1 out of 5Points: 10




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;
}
}
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
RIght Click Menu  .  DataGrid  .  Context options  .  Context Menu  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: DataGridView - Set Default values for New Row
Previous Resource: Auto Complete For a TextBox Control in DataGridView
Return to Discussion Resource Index
Post New Resource
Category: DataGridView


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use