【发布时间】:2013-05-21 20:32:21
【问题描述】:
我需要在显示 ContextMenu 之前右键单击 dataGridView 中的一行,因为 contextMenu 是行相关的。
我试过了:
if (e.Button == MouseButtons.Right)
{
var hti = dataGrid.HitTest(e.X, e.Y);
dataGrid.ClearSelection();
dataGrid.Rows[hti.RowIndex].Selected = true;
}
或:
private void dataGrid_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
dataGrid.Rows[e.RowIndex].Selected = true;
dataGrid.Focus();
}
}
这可行,但是当我尝试读取 dataGrid.Rows[CurrentRow.Index] 时,我只看到左键选择的行,而不是右键选择的行..
【问题讨论】:
标签: c# select datagridview row right-click