Hi,
You can simulate this by starting a new WinForm app.
Add a datagridview and add some columns.
Add a contextmenustrip, add a menuitem, doubleclick it to get a clickhandler.
Attach the menustrip to the datagridview in the properties window of the DGV.
Then refer to this code and the comments.
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
// here we do not come although the contextmenustrip shows up under the mouse pointer
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
this.contextMenuStrip1.Show(this.dataGridView1, new Point(e.RowIndex, e.ColumnIndex));
}
}
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
// here we do come but with the added effect that the contextmenu shows up in he upper right
// corner of the DGV before appearing under the mouse pointer as it should.
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
this.contextMenuStrip1.Show(this.dataGridView1, new Point(e.RowIndex, e.ColumnIndex));
}
}
private void removeColumnToolStripMenuItem_Click(object sender, EventArgs e)
{
// columnindex not always correct
this.dataGridView1.Columns.RemoveAt(this.dataGridView1.CurrentCell.ColumnIndex);
}
So with the mousedown I get the correct results with an extra menustrip popping up, with the mouseclick I get the correct menustrip but sometimes the wrong column gets deleted.
Can anyone explain what is happening, tried many things but I'm getting out of resources.
Any answer would be very much appreciated!