Results 1 to 13 of 13

Thread: [2003] FlexGrid Contextmenu

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    25

    [2003] FlexGrid Contextmenu

    I have a flexgrid and i have assigned it's contextmenu:

    Code:
    Flexgrid.ContextMenu = ContextMenu1
    
    ContextMenu1.Show(sender, New Point(e.x, e.y))
    THe problem is when i click the COntextMenu the Menu_Click is not triggered...

  2. #2

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    25

    Re: [2003] FlexGrid Contextmenu

    up up up

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2003] FlexGrid Contextmenu

    I don't understand that code. Why would you be assigning ContextMenu1 to the grid's ContextMenu property and then displaying the menu explicitly? Where exactly is that code? Have you handled the Click event of each menu item?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    25

    Re: [2003] FlexGrid Contextmenu

    Because when i only use:

    Code:
    Flexgrid.ContextMenu = ContextMenu1
    the menu doesn't popup.

    I have many flexgrid control and they are sharing this contextmenu and when a flexgrid use the menu, i want to determine which flexgrid calls or uses it.


    I also tried adding:

    Code:
    AddHandler MenuItem1.Click, AddressOf CMenuClick
    and
    Code:
    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
    'codes
        End Sub
    but no luck.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2003] FlexGrid Contextmenu

    There's no need for this line:
    vb.net Code:
    1. Flexgrid.ContextMenu = ContextMenu1
    When you call Show on the menu you pass a control to associate it with:
    Code:
    ContextMenu1.Show(sender, New Point(e.x, e.y))
    You can get that control back from the menu's SourceControl property.

    As to your issue of the menu item's not raising a Click event, I'm afraid I can be no help there as all i can tell you is that it should work.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    25

    Re: [2003] FlexGrid Contextmenu

    i've tried your suggestion but no luck the click event is still not firing.. but the select event is firing...


    ohhh..... i guess it's gonna be a long trial and error.... wheew...

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    25

    Re: [2003] FlexGrid Contextmenu

    any experts there... please help..

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2003] FlexGrid Contextmenu

    Please don't bump your thread after three hours. It was still in the top half of the first page so there's no justification for going against forum policy and reposting without asking a new question or providing new information.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2003] FlexGrid Contextmenu

    I have both VB6 and VS.NET 2003 installed here at work so I was able to test under the same conditions as you. In my testing the menu items also didn't raise their Click events, which is weird but, obviously, something to do with the fact that the grid is an ActiveX control rather than a .NET control. That's a good reason to avoid ActiveX if you can.

    Anyway, I was able to get around the issue by displaying the menu on the form instead of the grid:
    vb.net Code:
    1. Private lastGrid As AxMSFlexGrid
    2.  
    3. Private Sub AxMSFlexGrid1_MouseUpEvent(ByVal sender As Object, _
    4.                                        ByVal e As DMSFlexGridEvents_MouseUpEvent) Handles AxMSFlexGrid1.MouseUpEvent
    5.     If e.button = 2 Then
    6.         Me.lastGrid = DirectCast(sender, AxMSFlexGrid)
    7.         Me.ContextMenu1.Show(Me, Me.PointToClient(Me.AxMSFlexGrid1.PointToScreen(New Point(e.x, e.y))))
    8.     End If
    9. End Sub
    10.  
    11. Private Sub MenuItem1_Click(ByVal sender As Object, _
    12.                             ByVal e As EventArgs) Handles MenuItem1.Click
    13.     MessageBox.Show(sender.ToString(), "MenuItem1")
    14. End Sub
    15.  
    16. Private Sub MenuItem2_Click(ByVal sender As Object, _
    17.                             ByVal e As EventArgs) Handles MenuItem2.Click
    18.     MessageBox.Show(sender.ToString(), "MenuItem2")
    19. End Sub
    This obviously means that you can't use the SourceControl property to get the grid that was clicked, hence the extra field.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2003] FlexGrid Contextmenu

    Actually, I just did a bit more testing and it does work fine if you handle the ClickEvent event rather than the MouseUpEvent event. That led me to consider this:
    vb.net Code:
    1. Private rightClick As Boolean = False
    2.  
    3. Private Sub AxMSFlexGrid1_MouseUpEvent(ByVal sender As Object, _
    4.                                        ByVal e As DMSFlexGridEvents_MouseUpEvent) Handles AxMSFlexGrid1.MouseUpEvent
    5.     Me.rightClick = (e.button = 2)
    6. End Sub
    7.  
    8. Private Sub AxMSFlexGrid1_ClickEvent(ByVal sender As Object, _
    9.                                      ByVal e As EventArgs) Handles AxMSFlexGrid1.ClickEvent
    10.     If Me.rightClick Then
    11.         Dim grid As AxMSFlexGrid = DirectCast(sender, AxMSFlexGrid)
    12.  
    13.         Me.ContextMenu1.Show(grid, grid.PointToClient(Cursor.Position))
    14.     End If
    15. End Sub
    16.  
    17. Private Sub MenuItem1_Click(ByVal sender As Object, _
    18.                             ByVal e As EventArgs) Handles MenuItem1.Click
    19.     MessageBox.Show(Me.ContextMenu1.SourceControl.ToString(), "MenuItem1")
    20. End Sub
    21.  
    22. Private Sub MenuItem2_Click(ByVal sender As Object, _
    23.                             ByVal e As EventArgs) Handles MenuItem2.Click
    24.     MessageBox.Show(Me.ContextMenu1.SourceControl.ToString(), "MenuItem2")
    25. End Sub
    That still doesn't work though, so it seems that handling the MouseUpEvent simply messes something up. I then considered the MouseDownEvent event but it still didn't work. It seems to me that my previous solution might be the only one.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    25

    Re: [2003] FlexGrid Contextmenu

    the only problem if you view the menu in the form is that when you right click at any area in the form, the menu will appear. btw thanks for giving me a workaround...

    does it mean that contextmenu is not working on ActiveX controls?

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2003] FlexGrid Contextmenu

    Quote Originally Posted by cjtjamandra
    the only problem if you view the menu in the form is that when you right click at any area in the form, the menu will appear. btw thanks for giving me a workaround...
    You misunderstand. I didn't mean you should assign the menu to the form's ContextMenu property, nor did I mean you should display the menu on any of the form's events. What I meant was that you should pass the form to the first parameter of the menu's Show method instead of the grid, exactly as I coded it. You're still handling an event of the grid so the menu will still only be displayed when the grid is clicked.
    does it mean that contextmenu is not working on ActiveX controls?
    I've never specifically tested it on any other ActiveX controls so I don't know.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width