Solved

VB.net  Right click on DataGridView

Posted on 2014-02-03
6
2,658 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting C# Objects into JSON file 7 68
Form design in vb.net 7 35
Setting runtime form location 4 31
Make a border less form movable 2 23
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

19 Experts available now in Live!

Get 1:1 Help Now