In DataGridView
(C# WinForm app) I have programmed, if a row is selected and you right click on a RowHeader
, the ContextMenuStrip
is shown. It was meant the ContextMenuStrip
can show only if you click only on the RowHeader
:
private void myDataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right && e.RowIndex > -1)
{
if (myDataGridView.Rows[e.RowIndex].Selected == true)
{
if (myDataGridView.Rows[e.RowIndex].HeaderCell.ColumnIndex == e.ColumnIndex)
{
DataGridView ctrl = (DataGridView)sender;
ctrl.ContextMenuStrip = this.cmsBrisiPrekinitev;
ctrl.ContextMenuStrip.Show(e.Location);
}
}
}
}
Now, on the first row selection and right click on the RowHeader
it works fine, but after that the ContextMenuStrip
is shown no matter where inside the DataGridView
I do right click and I can't catch any event. An event for the left mouse click is raised properly.
How can I avoid this ContextMenuStrip
showing and what could be a reason for that?