?
Solved

Datagridview: contexmenustrip  vs. ColumnHeaderMouseClick right click

Posted on 2007-07-26
3
Medium Priority
?
1,375 Views
Last Modified: 2008-01-09
Hello. I am working with a datagridview.  I have a contextmenustrip on my form.  When I right click on a column header in the dgv, I want to do something.  The problem is, when I right click the header, the contexmenustrip pops up and the ColumnHeaderMouseClick never gets fired.  Is there a way around this?  
0
Comment
Question by:adwooley2
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 total points
ID: 19579854
Hello adwooley2,

Set the contextmenustrip property to nothing, then show the context menu via code....

    Private Sub DataGridView1_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
        If e.Button = Windows.Forms.MouseButtons.Right Then
            ContextMenuStrip1.Show(DataGridView1, New Point(e.X, e.Y))
        End If
    End Sub

Regards,

Wayne
0
 

Author Comment

by:adwooley2
ID: 19579889
That's really close, Wayne, I can feel it.
Here's what I want to do:

Header left clicked: Sort the dgv
Header right clicked: Run the freeze code
Right click anywhere else but header: show the contextmenustrip

Any way to do that? Sorry - I just can't seem to get it straight.
0
 

Author Comment

by:adwooley2
ID: 19580141
Wayne - appreciate you steering me the right way.  What I ended up doing was this:

Set the contextmenustrip property to nothing for datagridview
Loop through the rows and set the ContextMenuStrip = Me.ContextMenuStrip1.  This way, it doesn't set the columnheaders to have a contextmenustrip.

Regards,
Alan
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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

750 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