473,499 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop through MenuItems

1. How can I loop through all the items and subitems for Menu of a
Windows Form (c#) ? Recursive function?

2. How can I uniquely identify a submenu item ? MenuItems doesn't have
a Name property.
Thanks,
Steve
Nov 15 '05 #1
1 6688

"Steve Tan" <st********@yahoo.com> skrev i meddelandet
news:95**************************@posting.google.c om...
1. How can I loop through all the items and subitems for Menu of a
Windows Form (c#) ? Recursive function?
That's one possibility. Send the MenuItems from your MainMenu to this
example:

private void menuItems(Menu.MenuItemCollection mc)
{
foreach (MenuItem m in mc)
{
// Do whatever you like with
// the "single" item...

if (m.IsParent)
{
menuItems(m.MenuItems);
}
}
}

2. How can I uniquely identify a submenu item ?

MenuItems doesn't have a Name property.

How you need to identify a submenu item is depending on what you need to do.
Each object can be identified by the value of it's reference.

If you have more than one item with the same value in the Text-property,
maybe it should behave similar anyway.

If you absolutely need to have a Name property you can easily subclass the
MenuItem-class to your own specialized class.

class NamedMenuItem : MenuItem
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}

public NamedMenuItem () : base()
{
this.name = this.Text;
}
}

// Bjorn A

Nov 15 '05 #2

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

Similar topics

0
1333
by: Deutsche Dogge | last post by:
Hi. I'M having a weird problem with addign menuitems to a menu dynamically on the popup event of the menuitem containing the container of the menuitems i wanna add (tools -> external -> {list of...
14
6683
by: Yereth Jansen | last post by:
Hi all, I encountered a problem with looping through an associative array. All worked perfectly with the following code: for (var menuItem in this.menuItems) { doSomething(); } where...
0
1151
by: Kreisquadratur | last post by:
Below is s snippet of my code, which should add menuitems as a submenu of an item in a contextmenu. But only the first time the contextmenu opens the entrys are set correctly. I just don't know why...
0
1612
by: Brian | last post by:
Create a simple MDI form and a child form, and try the following simple code to add a new menu item on the Edit menu popup: private void editMenu_Popup(object sender, System.EventArgs e) {...
5
2007
by: Davie | last post by:
I'm developing an application on the smartphone. To reduce the size of the application i'm using panels where appropriate instead of forms. As a result of the design, I need to have different...
5
1746
by: Jorge Cavalheiro | last post by:
Hello I am trying to browse thru all menuitens of contextmenus. The form has 3 contextmenus. mi and mi2 as menuitems, f is a form For Each mi In f.ContextMenu.MenuItems For Each mi2 In...
8
5237
by: Dave | last post by:
I am trying to write an event-driven application with no main window that runs "forever". It waits on a named event and then displays a window depending on data pased in a memory-mapped file. I...
3
1368
by: active | last post by:
I have a mainmenu menuitem that contains a Recently Used Files menuitem If at design time I include a menuitem in the Recently Used Files menuitem collection it will display OK If I...
3
4828
by: MWS | last post by:
Hello, I'm trying to loop through the app.Config file and add the keys from the app.Config as MenuItems on a MenuStrip. The following line blows up... ...
0
7131
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
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7174
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,...
1
6894
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
5470
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
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.