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

x
?
Solved

using ContextMenuStrip with a datagridview does not show up

Posted on 2012-09-05
4
Medium Priority
?
1,078 Views
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
0
Comment
Question by:BKennedy2008
  • 3
4 Comments
 
LVL 48

Expert Comment

by:jpaulino
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.
0
 

Author Comment

by:BKennedy2008
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...

http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenustrip.aspx
0
 

Accepted Solution

by:
BKennedy2008 earned 0 total points
ID: 38367849
0
 

Author Closing Comment

by:BKennedy2008
ID: 38382284
found the answer
0

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 …
Progress

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