VB.NET Windows窗体上下文菜单位置

VB.NET Windows窗体上下文菜单位置,vb.net,properties,datagridview,position,contextmenu,Vb.net,Properties,Datagridview,Position,Contextmenu,我正在增强以前编写的VB.NET WIndows窗体应用程序 在其中一个表单中,有一个DataGridView,它是在表单加载时从存储过程填充的 如果用户有权限,当用户右键单击datagridview中的记录时,我想显示一个上下文菜单,允许用户删除该记录 这是我的密码: Private Sub m_SetEnabledContextMenu() ' for Delete record If Not objUser.HasAuthority("Delete Record") Then

我正在增强以前编写的VB.NET WIndows窗体应用程序

在其中一个表单中,有一个DataGridView,它是在表单加载时从存储过程填充的

如果用户有权限,当用户右键单击datagridview中的记录时,我想显示一个上下文菜单,允许用户删除该记录

这是我的密码:

Private Sub m_SetEnabledContextMenu()
  ' for Delete record
  If Not objUser.HasAuthority("Delete Record") Then
    Me.DataGridView1.ContextMenu = Nothing
    Me.mnuContextEquationSubmission.Enabled = False
  Else
    ' Me.DataGridView1.ContextMenu = Me.mnuContextEquationSubmission
    Me.mnuContextEquationSubmission.Enabled = True
  End If
  'Rest is not problem
End Sub

Private Sub DataGridView1_CellMouseDown(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) _
            Handles DataGridView1.CellMouseDown
  If e.Button = System.Windows.Forms.MouseButtons.Right Then
    For Each row As DataGridViewRow In DataGridView1.SelectedRows
      row.Selected = False
    Next
    DataGridView1.Rows(e.RowIndex).Selected = True

    'MessageBox.Show("DataGridView1_CellMouseDown on row " & e.RowIndex.ToString)
    m_intSelRow = e.RowIndex
    m_intSelCol = e.ColumnIndex

    m_strRecordID = DataGridView1.Rows(e.RowIndex).Cells(0).Value

    'mnuContextEquationSubmission.Show(DataGridView1, e.Location)
    mnuContextEquationSubmission.Show(CType(sender, Control), e.Location)
  End If
End Sub
如您所见,在“m_SetEnabledContextMenu”过程中,我确定用户是否有权删除记录,因此上下文菜单将被激活,或者至少,这是我想要的-当用户没有权限时,菜单应不可见并被禁用

在事件处理程序DataGridView1_CellMouseDown中,如果是右键单击,并且用户在数据行中单击,则我希望上下文菜单显示鼠标所在的位置,而不是顶部

使用mnuContextEquationSubmission.ShowMe,Me.PointToClientMousePosition

使用mnuContextEquationSubmission.ShowMe,Me.PointToClientMousePosition