C# DataGridView相当于Listbox';s IndexFromPoint

C# DataGridView相当于Listbox';s IndexFromPoint,c#,winforms,datagridview,listbox,C#,Winforms,Datagridview,Listbox,是否存在与ListBox的IndexFromPoint方法等效的DataGridView?我需要它,这样我可以在右键单击某个给定单元格时选择该单元格,虽然左键单击确实会选择该单元格,但它似乎无法正常检测到该单元格。当我使用列表框时,我通过使用IndexFromPoint方法实现了这一点,这就是为什么我在这里提出它。尝试使用CellContentClick事件。确保验证当用户右键单击列标题时,要处理的行索引大于0 private void dataGridView1_CellMouseClick(

是否存在与ListBox的IndexFromPoint方法等效的DataGridView?我需要它,这样我可以在右键单击某个给定单元格时选择该单元格,虽然左键单击确实会选择该单元格,但它似乎无法正常检测到该单元格。当我使用列表框时,我通过使用IndexFromPoint方法实现了这一点,这就是为什么我在这里提出它。

尝试使用
CellContentClick
事件。确保验证当用户右键单击列标题时,要处理的
行索引
大于0

private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
     if (e.Button == System.Windows.Forms.MouseButtons.Right && e.RowIndex >= 0)
     {
           dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
     }
 }