Home All Groups Group Topic Archive Search About
Author
9 May 2007 11:30 AM
AVL
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?

Author
9 May 2007 8:55 PM
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.

AddThis Social Bookmark Button