Solved

VB.net  Right click on DataGridView

Posted on 2014-02-03
6
2,823 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
[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: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
Technology Partners: 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!

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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