473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Dynamically Adding Menu Items

Hello,

I need to dynamically add menu items to an existing menu on an MDI form. In
the form load, when I create the menu items then add it to the menu control
using the Add method, the entire menu dissappears. Any one know why?

Below is the code I'm using to create the menu items and append them to the
existing menu:

Dim aDatasheets As ArrayList = gOSSystemFile.Datasheets
Dim oDatasheet As OSSystem.OSDatasheet
Dim mnuDatasheet As MenuItem

' existing top level menu item
mnuDatasheet = Me.mnuDatasheets

' add a submenu item for each datasheet in our set
For Each oDatasheet In aDatasheets
Dim mnuTemp As New MenuItem
mnuTemp.Text = oDatasheet.Name
mnuDatasheet.MenuItems.Add(mnuTemp)
Next
Thanks in advance.
Jack
Nov 21 '05 #1
2 2279
Jack,

I created a class to define objects that could be used as sources for new menus:

Public Class MenuItemSource
' Name field.
Private _Name As String

' Name property.
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property

Public Sub New(ByVal menuName As String)
Me.Name = menuName
End Sub
End Class

Next, I added this code to a MDI form:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim menuItemSources As New ArrayList()
menuItemSources.Add(New MenuItemSource("New Menu1"))
menuItemSources.Add(New MenuItemSource("New Menu2"))
Dim typeMenuItemSource As MenuItemSource
For Each typeMenuItemSource In menuItemSources
Dim newMenuItem As New MenuItem()
newMenuItem.Text = typeMenuItemSource.Name
Me.FileMenuItem.MenuItems.Add(newMenuItem)
Next
End Sub
It all worked just fine.

Are you sure about the data being used in your example?
--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

"jack" <ja***@systemsynergy.com.dumpthispart> wrote in message news:O3**************@tk2msftngp13.phx.gbl...
Hello,

I need to dynamically add menu items to an existing menu on an MDI form. In
the form load, when I create the menu items then add it to the menu control
using the Add method, the entire menu dissappears. Any one know why?

Below is the code I'm using to create the menu items and append them to the
existing menu:

Dim aDatasheets As ArrayList = gOSSystemFile.Datasheets
Dim oDatasheet As OSSystem.OSDatasheet
Dim mnuDatasheet As MenuItem

' existing top level menu item
mnuDatasheet = Me.mnuDatasheets

' add a submenu item for each datasheet in our set
For Each oDatasheet In aDatasheets
Dim mnuTemp As New MenuItem
mnuTemp.Text = oDatasheet.Name
mnuDatasheet.MenuItems.Add(mnuTemp)
Next


Thanks in advance.
Jack

Nov 21 '05 #2
It took me a while, but I figured out what the problem was.

The app in question is currently being converted from VB6 app to .NET.
Because VB6 did not support docking, the app had a picture box on the MDI
form into which another form is loaded, thus acting as if it is docked. As
it turns out, somehow the issue is related to the picture box and loading a
form into it. Once I dumped the picture box, the menu issue was resolved.
Part of my task to fully convert this app to .NET is to get rid of the
picture box. It just happened sooner than I planned.

Thanks!
Jack
"Mike McIntyre [MVP]" <mi****@getdotnetcode.com> wrote in message
news:ed*************@TK2MSFTNGP15.phx.gbl...
Jack,

I created a class to define objects that could be used as sources for new
menus:

Public Class MenuItemSource
' Name field.
Private _Name As String

' Name property.
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property

Public Sub New(ByVal menuName As String)
Me.Name = menuName
End Sub
End Class

Next, I added this code to a MDI form:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim menuItemSources As New ArrayList()
menuItemSources.Add(New MenuItemSource("New Menu1"))
menuItemSources.Add(New MenuItemSource("New Menu2"))
Dim typeMenuItemSource As MenuItemSource
For Each typeMenuItemSource In menuItemSources
Dim newMenuItem As New MenuItem()
newMenuItem.Text = typeMenuItemSource.Name
Me.FileMenuItem.MenuItems.Add(newMenuItem)
Next
End Sub
It all worked just fine.
Are you sure about the data being used in your example?

--
Mike
Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

"jack" <ja***@systemsynergy.com.dumpthispart> wrote in message
news:O3**************@tk2msftngp13.phx.gbl...
Hello,

I need to dynamically add menu items to an existing menu on an MDI form.
In
the form load, when I create the menu items then add it to the menu
control
using the Add method, the entire menu dissappears. Any one know why?

Below is the code I'm using to create the menu items and append them to
the
existing menu:

Dim aDatasheets As ArrayList = gOSSystemFile.Datasheets
Dim oDatasheet As OSSystem.OSDatasheet
Dim mnuDatasheet As MenuItem

' existing top level menu item
mnuDatasheet = Me.mnuDatasheets

' add a submenu item for each datasheet in our set
For Each oDatasheet In aDatasheets
Dim mnuTemp As New MenuItem
mnuTemp.Text = oDatasheet.Name
mnuDatasheet.MenuItems.Add(mnuTemp)
Next
Thanks in advance.
Jack


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Claire | last post by:
When I run the following code through on the first round, my sub-menu (branched off mnuOpenPorts menuitem) shows a nice list of ports. When it gets run through on the 2nd pass, the sub menu...
1
by: Joe | last post by:
I have a MenuItem which is was added to the context menu at design time. The context menu is for a button on a toolbar. At runtime I add and remove sub-menuitems to and from this menu item. The...
10
by: tmaster | last post by:
When I try to dynamically add a second sub menu item to this ContextMenu item, I get an error 'Specified argument was out of the range of valid values'. Private Sub mnuTopics_Show_Select(ByVal...
7
by: Steve_Black | last post by:
Hello, I'm toying with the idea of loading a MenuStrip (VB.Net 2005) dynamically based on who is logged into my system. Every user has different security settings and I want to customize the...
12
by: Steve_Black | last post by:
I posted a similar message earlier but we've geared away from the original topic somewhat so I thought I'd post again in hopes of getting input from others. I am creating a MenuStrip...
0
by: Przemek | last post by:
Hi, I'm trying to create menu dynamically (populated with dataset). I want to have it inside my div, which is inside another div and inside contentplaceholder. Unfortunately I'm receiving null...
4
windows_mss
by: windows_mss | last post by:
When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map... hi, i can able to get the Correct Route and Path for the corresponding Source and destination, like...
0
by: Puja | last post by:
hi all, I have asp.net menu control on my page. I want to hide some menu and sub-menu items dynamically depending on user. (i.e after user is logged in) is there any property like ...
6
by: Luqman | last post by:
How can I dynamically Add menuStrip and its menuItems through code using VB.Net 2005 ? Best Regards, Luqman
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.