DataGridView右击选择一行并显示菜单。

 

 在列标题处单击和在内容处单击弹出不同菜单

Private Sub DataGridView1_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView.CellMouseDown

      If e.Button = Windows.Forms.MouseButtons.Right Then
            If e.RowIndex < 0 Then
                  Me.DataGridView1.ClearSelection()
                  Me.菜单1.Show(MousePosition.X, MousePosition.Y)
            Else
                  Me.DataGridView1.ClearSelection()
                  Me.DataGridView1.Rows(e.RowIndex).Selected = True
                  Me.菜单2.Show(MousePosition.X, MousePosition.Y)
            End If
      End If
End Sub

你可能感兴趣的:(datagridview)