Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.net  Right click on DataGridView

Posted on 2014-02-03
6
Medium Priority
?
3,177 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Murray Brown
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Murray Brown
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 2000 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:Murray Brown
ID: 39830564
Thanks very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

650 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