I have a datagridview where I show infomation about products. I want to bind a contextmenu when the user selects a cell and then right clicks on that cell. I have another contextmenu and that one is bound to the columns of the datagridview. If a user right clicks on a column the contextmenu shows.
I have tried like this but it does not work. The context menu shows when the user right clicks on a cell, but the contextmenu that is bound to the column header does not work.
private void GridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
productContextMenu.Show(GridView1, e.Location);
}
}How do I make it so that when the user right clicks on a datagridview shows up?
Thanx in advance.

Dorababu MekaRank #457 · 5.5K reputationPosted Jun 8, 2011, 4:06 AM EDT
private void dataGridView_MouseUp(object sender, MouseEventArgs e) { // Load context menu on right mouse click DataGridView.HitTestInfo hitTestInfo; if (e.Button == MouseButtons.Right) { hitTestInfo = dataGridView.HitTest(e.X, e.Y); // If column is first column if (hitTestInfo.Type == DataGridViewHitTestType.Cell && hitTestInfo.ColumnIndex == 0) contextMenuForColumn1.Show(dataGridView, new Point(e.X, e.Y)); // If column is second column if (hitTestInfo.Type == DataGridViewHitTestType.Cell && hitTestInfo.ColumnIndex == 1) contextMenuForColumn2.Show(dataGridView, new Point(e.X, e.Y)); } }