datagridview .net 2.0

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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.
 
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?

See properties "DataGridView.ContextMenuStrip",
"DataGridViewColumn.ContextMenuStrip" and
"DataGridViewRow.ContextMenuStrip". Note that you can usually handle things
using the forms designer. Drag a "ContextMenuStrip" from the tools box onto
your form. You can then select it from the grid's "ContextMenuStrip"
property (it appears in the dropdown list). Add items to it accordingly
using the designer. Note that the menu will apply to entire grid in this
case. You can set the same property on individual rows and columns however
(well, columns anyway - don't recall if the designer provides row support)
 
Back
Top