I have a flexgrid and i have assigned it's contextmenu:
THe problem is when i click the COntextMenu the Menu_Click is not triggered...Code:Flexgrid.ContextMenu = ContextMenu1
ContextMenu1.Show(sender, New Point(e.x, e.y))
Printable View
I have a flexgrid and i have assigned it's contextmenu:
THe problem is when i click the COntextMenu the Menu_Click is not triggered...Code:Flexgrid.ContextMenu = ContextMenu1
ContextMenu1.Show(sender, New Point(e.x, e.y))
Look at the Opening event.
up up up
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?
Because when i only use:
the menu doesn't popup.Code:Flexgrid.ContextMenu = ContextMenu1
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:
andCode:AddHandler MenuItem1.Click, AddressOf CMenuClick
but no luck.Code:Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
'codes
End Sub
There's no need for this line:When you call Show on the menu you pass a control to associate it with:vb.net Code:
Flexgrid.ContextMenu = ContextMenu1You can get that control back from the menu's SourceControl property.Code:ContextMenu1.Show(sender, New Point(e.x, e.y))
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.
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...
any experts there... please help..
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.
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:This obviously means that you can't use the SourceControl property to get the grid that was clicked, hence the extra field.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
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: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.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
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?
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.Quote:
Originally Posted by cjtjamandra
I've never specifically tested it on any other ActiveX controls so I don't know.Quote:
does it mean that contextmenu is not working on ActiveX controls?