VB6 popup (contect menu)

I've followed the code in this example:  http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_20942908.html  but still cannot get my menu to work.

I'm creating an ActiveX control in VB6 and created a menu using the menu editor that looks like this:

....Move Up
....Move Down

with names nodemenu, nodemenuup and nodemenudown respectively.

Then in my code I have the following relevent bits:

Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then
        popupmenu nodemenu
    End If
End Sub

When I run it and right click on the control I get the error:  428 popup menu must have at least one submenu

I tried creating this on a seperate form and that didn't seem to have any effect.

Any ideas?

For bonus points how do I then assign code to the menu click events?
Who is Participating?
PAQed with no points refunded (of 150)

Community Support Moderator
For Run time "428 popup menu must have at least one submenu"

In order to display popup menu all your menus should be child menu.

Top level menus cannot be displayed with popup.

....Move Up
....Move Down

in above code you can display move up and move down menus by calling  "Popupmenu pop". Same way "nodemenu" should have some child menus to display them in the popup menu.

For each Child menus add in the menu editor , the associated click events will be shown in the code pane where you can implement.

Click events will not be avaliable for top level menus.

Hope it helps.


djguvnorAuthor Commented:
I don't understand,  my top level menu item is:
Caption: Pop
Name: nodemenu

It has 2 children
Caption: Move Up
Name: nodemenuup


Caption: Move Down
Name: nodemenudown

So when I call:
popupmenu nodemenu
surely that is calling a menu with 2 submenus?

I'm obviously missing something fundamental here!  All I want is a popup menu with Move Up and Move Down on it!
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Carl TawnSystems and Integration DeveloperCommented:
It sounds like you haven't actually got your submenu items indented properly, so VB doesn't think they are actually child items.

As far as handling the click events for each menu goes. Each menu item is available like any other control.  If you click the left-hand combo box at the top of the VB editor window, each of you menu items should be listed. Just select the one you're interested in and it should create the outline for you. Something like:

    Private Sub mnunodeup_Click()
        '// Code to run when menu item clicked
    End Sub

Hope this helps.
djguvnorAuthor Commented:
"It sounds like you haven't actually got your submenu items indented properly"

They look like child items.  How else do you add child items?  There's no 'add child item' button in fact the user interface of the menu editor doesn't make a whole lot of sense but either way my menu still doesn't work and now this is getting silly.  Someone must know how to do this?
me.popupmenu nodemenu

maybe they shud be hidden first.

i dont know whats wrong, i created the menus u made and it works fine.
djguvnorAuthor Commented:
Do you think it makes any difference that I'm doing it on an ActiveX control and not a form?
oh i forgot. it is because of that. ull have to set properties and stuff to make the popup appear when the activex control is placed on a form.
djguvnorAuthor Commented:
how do I do that?
i dont really know bout activex controls. other experts any help ?
There is no explicit properties to be set for displaying popup from activex control.
Try these steps and tell me if you still get the same error -
How to add menu -
1. Open your activeX control and goto Tools -> Menu Editor.

2. Add new items lets say
File (name: mnuFile)
Now click the Next button and then click arrow which is indicating to Right (->)
Add subitem lets say New (name: mnuName)
Now again click the Next button and then again click arrow which is indicating to Right (->)
Add subitem lets say Close (name: mnuClose)

3. Now select File from the list that is displayed on the same dislog box and set Visible to false by make it unchecked.

By doing this you are having one Menu item (File) and two subitems (New and Close)

Now test your ActiveX control on the test project. Rest is the same as you were doing before.
The entire problem is likely because you did not specify the index data for the child popup menus....

In the menu editor, select your popup menu, ensure that the index for the popup menu title is not set, then foro each child item make sure you set each one to a numeric value .. in your case 1 and 2

Make sure they are marked as visible while the top level menu is not marked as visible.

To easily make the menu items code wrapper for your code, simply turn on visibility for the menu, view the control in the IDE and select the menu item, the code window should open and allow you to complete the code as needed. Repeat for the other menu item.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.