Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


using ContextMenuStrip with a datagridview does not show up

Posted on 2012-09-05
Medium Priority
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
  • 3
LVL 48

Expert Comment

ID: 38367615
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

ID: 38367670
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

BKennedy2008 earned 0 total points
ID: 38367849

Author Closing Comment

ID: 38382284
found the answer

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

564 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