Solved

VB.net  Right click on DataGridView

Posted on 2014-02-03
6
2,738 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
ID: 39830051
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
ID: 39830105
Thanks James. How do I get it to pop up with a button on it that runs some code?
0
 
LVL 40
ID: 39830161
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 

Author Comment

by:murbro
ID: 39830233
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
ID: 39830539
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
ID: 39830564
Thanks very much
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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