DataGridView 上的右 clic 返回在其中创建右 clic 的单元格索引



我将ContextMenuStrip附加到DataGridView,但它将执行的操作将基于用户右键单击的行。

我能够从左键单击中检索坐标,但没有称为 CellRightClick 的事件,只有 CellClick 或 CellMouseClick...等。然而,我在网上读到可以跟踪细胞的位置I/O,但我想要一个更简单的解决方案,因为下一步是触摸屏系统的便携性。

编辑:幸运的是,当我右键单击并弹出我的上下文菜单时,它也被视为CellMouseLeave事件,因此:

Private Sub t(Sender As Object, E As DataGridViewCellEventArgs) Handles DataGridView1.CellMouseLeave
    LastRightClickedRowIndex = E.RowIndex
End Sub

可能有效吗?你觉得怎么样?它是固体吗?

可以使用

由于用户右键单击单元格而需要单元格快捷菜单时发生的DataGridView CellContextMenuStripNeeded事件。

Private Sub DataGridView1_CellContextMenuStripNeeded(
    sender As Object, 
    e As System.Windows.Forms.DataGridViewCellContextMenuStripNeededEventArgs) 
    Handles DataGridView1.CellContextMenuStripNeeded
    MsgBox("You click row " & e.RowIndex & " / column " & e.ColumnIndex & "!")
End Sub

最新更新