I need to select a row in dataGridView with right click before ContextMenu shown because contextMenu is row-dependendt.
I\'ve tried this:
if (e.Butt
Try setting the current cell like this (this will set the CurrentRow property of the DataGridView before the context menu item is selected):
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
var dataGrid = (DataGridView) sender;
if (e.Button == MouseButtons.Right && e.RowIndex != -1)
{
var row = dataGrid.Rows[e.RowIndex];
dataGrid.CurrentCell = row.Cells[e.ColumnIndex == -1 ? 1 : e.ColumnIndex];
row.Selected = true;
dataGrid.Focus();
}
}