Adding elements to a control array of Menu items with subMenus at Run time 
Author Message
 Adding elements to a control array of Menu items with subMenus at Run time

Hi all

I have a wee problem.

At design time I have created a Menu item (mnuOpen) with one sub-item
(mnuOpenPost) which is element 0 of a control array.  I can happily add and
remove at run time new elements to this control array, i.e. mnuOpenPost (1),
(2) etc. using:

Load mnuOpenPost(1)

================

mnuOpenpost(0) has a sub-menu consisting of two items - mnuOpenPostReformat
and mnuOpenPostClose.

I want my new instances of mnuOpenPost to each have the same sub-menu.  But
I'm not sure how to do this.

If at design time I make mnuOpenpostReformat and mnuOpenPostClose each
element 0 of a control array, I can add new instances of them using:

Load mnuOpenPostReformat(1)
Load mniOpenPostClose(1)

etc.

*But* - these new elements get added to mnuOpenpost(0), when I want to add
them to mnuOpenPost(1)

I'm sure there's a straightforward answer, but I've not had to add Menu
items at run time up till now.  MSDN Help is fairly cursory about control
arrays of Menu items.

Any ideas?

Christina




Thu, 18 Sep 2003 00:22:02 GMT  
 Adding elements to a control array of Menu items with subMenus at Run time
Christina ...

Are you saying that you have:

mnuOpen
  mnuOpenPost (0)
     mnuOpenPostReformat
     mnuOpenPostClose

and at runtime want to add new items such that the resulting menu looks
like:

mnuOpen
  mnuOpenPost (0)
     mnuOpenPostReformat
     mnuOpenPostClose

  mnuOpenPost (1)
     mnuOpenPostReformat
     mnuOpenPostClose

  mnuOpenPost (2)
    mnuOpenPostReformat
    mnuOpenPostClose

etc ...

This is not possible using VB, since to add submenus to any item, that item
must exist at design time. This means the best you can do is end up with:

mnuOpen
  mnuOpenPost (0)
    mnuOpenPostReformat
    mnuOpenPostClose

As you've discovered, changing the close and reformat items to menu arrays,
then Loading addtional members, only results in

mnuOpen
  mnuOpenPost (0)
    mnuOpenPostReformat (0)
    mnuOpenPostReformat (1)
    mnuOpenPostReformat (2)
    mnuOpenPostClose (0)
    mnuOpenPostClose (1)
    mnuOpenPostClose (2)

  mnuOpenPost (1)
  mnuOpenPost (2)
etc...

So unless you know exactly how many items require submenus, and create each
with one member, you'll have to rethink the way your menus will work, or
turn to the api and subclassing to handle every aspect of the menu creation,
display, and selection. The former suggestion is the one I'd be inclined to
take.

--

Randy Birch
MVP Visual Basic

Take the vb.net poll at:
http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please respond only to the newsgroups so all can benefit.


: Hi all
:
: I have a wee problem.
:
: At design time I have created a Menu item (mnuOpen) with one sub-item
: (mnuOpenPost) which is element 0 of a control array.  I can happily add
and
: remove at run time new elements to this control array, i.e. mnuOpenPost
(1),
: (2) etc. using:
:
: Load mnuOpenPost(1)
:
: ================
:
: mnuOpenpost(0) has a sub-menu consisting of two items -
mnuOpenPostReformat
: and mnuOpenPostClose.
:
: I want my new instances of mnuOpenPost to each have the same sub-menu.
But
: I'm not sure how to do this.
:
: If at design time I make mnuOpenpostReformat and mnuOpenPostClose each
: element 0 of a control array, I can add new instances of them using:
:
: Load mnuOpenPostReformat(1)
: Load mniOpenPostClose(1)
:
: etc.
:
: *But* - these new elements get added to mnuOpenpost(0), when I want to add
: them to mnuOpenPost(1)
:
: I'm sure there's a straightforward answer, but I've not had to add Menu
: items at run time up till now.  MSDN Help is fairly cursory about control
: arrays of Menu items.
:
: Any ideas?
:
: Christina
:

:
:
:
:
:



Thu, 18 Sep 2003 03:18:58 GMT  
 Adding elements to a control array of Menu items with subMenus at Run time


Quote:
> Christina ...
> Are you saying that you have:
> [...]

Yes, Randy, that's exactly right.

Thanks so much for the information.  I'm gonna have to have a rethink...:)

Christina




Thu, 18 Sep 2003 03:31:13 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Create Control Array and add item at run time

2. add item menu in control menu when app is run

3. Run time error 340 - control array element does not exist

4. Adding menu items at run-time

5. Code to add menu items at run time.

6. Adding Menu item at run-time

7. Adding menu items at run-time?

8. Adding menu items at run-time

9. How to add menu items at run time?

10. Adding menu items at run time

11. adding menu items at run time

12. Adding menu items at run time

 

 
Powered by phpBB® Forum Software