Can someone direct me to a reference that describes how to create a
context menu for a selected row in a datagrid? I have come across many
threads regarding context menus and datagrids but they all seem to be
how to modify the default behavior. I've gone through a couple of books
and many threads but none of these seem to discuss creating a context
menu for a given row. I did come across a thread that allowed me to
create a menu for the entire grid but that even allows for a context
menu outside of any rows.
thanks for your help
john
ClayB - 22 Jan 2007 10:58 GMT
You can catch a right click in the grid.MouseDown event and display the
contextmenu at that point if you are over the row where you want the
menu. Here is a little snippet that displays it over row 3. (Do not set
the dataGrid1.ContextMenu property if you want to only see the menu
over certain rows.)
private void dataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo info = dataGrid1.HitTest(pt);
if(info.Row == 3)
{
this.contextMenu1.Show(this.dataGrid1, pt);
}
}
}
=================
Clay Burch
Syncfusion, Inc.