datagridview

G

Guest

hi,
ive a datagridview cotrol on my winform..
i want to show a contextmenustrip when i right click a cell or row of my
grid...
how can i acheive it?
 
C

ClayB

One way you can do this is to handle the CellMouseUp event.

void dataGridView1_CellMouseUp(object sender,
DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
DataGridView grid = sender as DataGridView;
ContextMenuStrip menu = new ContextMenuStrip();
menu.Items.Add("Task1", null, new
EventHandler(Task1_Click));
menu.Items.Add("Task2", null, new
EventHandler(Task2_Click));
Point pt = grid.PointToClient(Control.MousePosition);
menu.Show(dataGridView1, pt.X, pt.Y);
}
}

====================
Clay Burch
Syncfusion, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top