Solved

VB.net  Right click on DataGridView

Posted on 2014-02-03
6
2,605 Views
Last Modified: 2014-02-03
Hi

In the code below, which I found at the bottom of the following page
http://www.codeproject.com/Questions/518882/vb-net-2cplusDatagridViewplusContextplusMenuplusSt

The Context Menu Strip isn't showing. How do I get it to pop up at the right click point
and how do I run code to delete a cell?
 

Private Sub DgvDelays_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DgvDelays.CellMouseDown
        Dim rowClicked As DataGridView.HitTestInfo = DgvDelays.HitTest(e.X, e.Y)
 
        'Select Right Clicked Row if its not the header row
        If e.Button = Windows.Forms.MouseButtons.Right AndAlso e.RowIndex > -1 Then
            'Clear any currently sellected rows
            DgvDelays.ClearSelection()
            Me.DgvDelays.Rows(e.RowIndex).Selected = True
            CmsRightClick.Show(DgvDelays, New System.Drawing.Point(MouseX, MouseY))
        End If
 

    End Sub
0
Comment
Question by:murbro
  • 3
  • 3
6 Comments
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
The code provided in the article you point to is incomplete. See the comments at the bottom of the page.

I suspect that CmsRightClick is a ContextMenuStrip, but it is not defined anywhere in the code.
0
 

Author Comment

by:murbro
Comment Utility
Thanks James. How do I get it to pop up with a button on it that runs some code?
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
I do not understand your last question.

What do you want to pop up? A ContextMenuStrip? There are no "buttons" on a ContextMenuStrip, only menu items.

Do you already have a ContextMenuStrip on your form?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:murbro
Comment Utility
Hi
Yes please I need a ContextMenuStrip to pop up....I aready have one on my form. I just need the user to be able to clear the content of the cell
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
Once you have a ContextMenu on the form, you must :

1. Click on the menu in the component tray (bottom of the form). The menu will appear temporarily where the standard menu usually shows, at the top of the form. With a right click in that menu, you will be able to add entries for the menu. A double click on an entry will enable you to react to the Click event on that entry.

2. To associate the context menu with a given control, such as a TextBox, click on the TextBox in the designer, and then, under the ContextMenuStrip property, in the Properties window, select the menu that you want to associate with that TextBox.

The menu will automatically show when the user right-click on the TextBox.
0
 

Author Closing Comment

by:murbro
Comment Utility
Thanks very much
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

18 Experts available now in Live!

Get 1:1 Help Now