using ContextMenuStrip with a datagridview does not show up

Posted on 2012-09-05
Last Modified: 2012-09-10
What am I missing here to be able to use right click.

 I created a form, added a contextmenustrip with items, then created a new instance and added a datagridview1, however, the contextmenu does not show up. here is the code:

Public Class Locations

    Public dataGridView2 As New DataGridView()
    Public bindingSource2 As New BindingSource()
    Public dataAdapter2 As New SqlDataAdapter()
    Private WithEvents EditButton As New Button()
    Private WithEvents DeleteButton As New Button()
    Private WithEvents NewButton As New Button()
    Private WithEvents SearchTextBox As New ComboBox
    Private WithEvents SearchButton As New Button()
    Private WithEvents ViewAllButton As New Button()
    <STAThreadAttribute()> _
    Public Shared Sub Main1()
        Application.Run(New Locations())
    End Sub
    Public Sub New()

        Me.dataGridView2.Dock = DockStyle.Fill
        Me.SearchTextBox.Width = 300
        Me.EditButton.Text = "Edit Location"
        Me.DeleteButton.Text = "Delete Location"
        Me.NewButton.Text = "New Location"
        Me.SearchButton.Text = "Search for Job name/ number"
        Me.SearchButton.Width = 180
        Me.ViewAllButton.Text = "View All (Reset)"
        Me.NewButton.Width = 130
        Me.EditButton.Width = 130
        Me.DeleteButton.Width = 130
        Me.ViewAllButton.Width = 130

        Me.dataGridView2.ContextMenuStrip = ContextMenuStrip1        Me.AcceptButton = SearchButton
        Dim panel As New FlowLayoutPanel()
        Me.ControlBox = False

        panel.Dock = DockStyle.Top
        panel.AutoSize = True
        panel.Controls.AddRange(New Control() {Me.SearchTextBox, Me.SearchButton, Me.NewButton, Me.EditButton, Me.DeleteButton, Me.ViewAllButton})

        Me.Controls.AddRange(New Control() {Me.dataGridView2, panel})
        Me.Text = "ALL  JOBS/ LOCATIONS"

    End Sub
Question by:BKennedy2008
    LVL 48

    Expert Comment

    then created a new instance

    If you add a contextmenustrip to the form you don't need to create a new instance of it ... it's already created in codebehind.

    Author Comment

    I meant created a new instance of the form, not the contextstripmenu.
    I think I have to write all the code out for a contextmenustrip, but seems like something easier than this...

    Accepted Solution


    Author Closing Comment

    found the answer

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now