|
-
Sep 24th, 2008, 02:38 AM
#1
Thread Starter
Junior Member
[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...
-
Sep 24th, 2008, 03:45 AM
#2
Re: [2003] FlexGrid Contextmenu
Look at the Opening event.
-
Sep 28th, 2008, 08:33 PM
#3
Thread Starter
Junior Member
Re: [2003] FlexGrid Contextmenu
-
Sep 28th, 2008, 09:13 PM
#4
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?
-
Sep 28th, 2008, 09:43 PM
#5
Thread Starter
Junior Member
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.
-
Sep 28th, 2008, 10:11 PM
#6
Re: [2003] FlexGrid Contextmenu
There's no need for this line:
vb.net Code:
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.
-
Sep 28th, 2008, 10:27 PM
#7
Thread Starter
Junior Member
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...
-
Sep 29th, 2008, 01:49 AM
#8
Thread Starter
Junior Member
Re: [2003] FlexGrid Contextmenu
any experts there... please help..
-
Sep 29th, 2008, 02:01 AM
#9
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.
-
Sep 29th, 2008, 02:10 AM
#10
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:
Private lastGrid As AxMSFlexGrid Private Sub AxMSFlexGrid1_MouseUpEvent(ByVal sender As Object, _ ByVal e As DMSFlexGridEvents_MouseUpEvent) Handles AxMSFlexGrid1.MouseUpEvent If e.button = 2 Then Me.lastGrid = DirectCast(sender, AxMSFlexGrid) Me.ContextMenu1.Show(Me, Me.PointToClient(Me.AxMSFlexGrid1.PointToScreen(New Point(e.x, e.y)))) End If End Sub Private Sub MenuItem1_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles MenuItem1.Click MessageBox.Show(sender.ToString(), "MenuItem1") End Sub Private Sub MenuItem2_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles MenuItem2.Click MessageBox.Show(sender.ToString(), "MenuItem2") End Sub
This obviously means that you can't use the SourceControl property to get the grid that was clicked, hence the extra field.
-
Sep 29th, 2008, 02:21 AM
#11
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:
Private rightClick As Boolean = False Private Sub AxMSFlexGrid1_MouseUpEvent(ByVal sender As Object, _ ByVal e As DMSFlexGridEvents_MouseUpEvent) Handles AxMSFlexGrid1.MouseUpEvent Me.rightClick = (e.button = 2) End Sub Private Sub AxMSFlexGrid1_ClickEvent(ByVal sender As Object, _ ByVal e As EventArgs) Handles AxMSFlexGrid1.ClickEvent If Me.rightClick Then Dim grid As AxMSFlexGrid = DirectCast(sender, AxMSFlexGrid) Me.ContextMenu1.Show(grid, grid.PointToClient(Cursor.Position)) End If End Sub Private Sub MenuItem1_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles MenuItem1.Click MessageBox.Show(Me.ContextMenu1.SourceControl.ToString(), "MenuItem1") End Sub Private Sub MenuItem2_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles MenuItem2.Click MessageBox.Show(Me.ContextMenu1.SourceControl.ToString(), "MenuItem2") 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.
-
Sep 29th, 2008, 03:05 AM
#12
Thread Starter
Junior Member
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?
-
Sep 29th, 2008, 03:15 AM
#13
Re: [2003] FlexGrid Contextmenu
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|