473,327 Members | 2,074 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,327 software developers and data experts.

Menu how to figured out

I got my menu stuff figured out. I created a main menu with one menu item
(menuItem1). When selected, it fills in submenu items and links them to a
click method. On each select, the subitems are cleared out.

I have two more questions

1. When I do the RemoveAt, is the link to the clicker method obliterated?
It seems ok. I don't want to keep adding things into the list.
2. It there an easier way to do the RemoveAt loop, like in one fell swoop?
private void menuItem1_Select(object sender, System.EventArgs e)
{
for(int si=menuItem1.MenuItems.Count-1; si>=0;si--)
{
menuItem1.MenuItems.RemoveAt(si);
}

string[] astrWindow={"111", "222", "333", "444", "555"};
for(int si=0; si<astrWindow.Length;si++)
{
MenuItem filemenu = new MenuItem();
filemenu.Click += new System.EventHandler(this.fmClick);
filemenu.Text = astrWindow[si];;
menuItem1.MenuItems.Add(filemenu);
}
}

private void fmClick(object sender, System.EventArgs e)
{
MessageBox.Show(((MenuItem)sender).Text);
}
Nov 16 '05 #1
1 1112
Yes, when you remove the item from the list, the reference
to the event handler is also removed provided there are no
other references to the menu item you have just removed.

To nuke all of the MenuItems from a MenuItems collection,
simply call the Clear() method on it.

So in your example, you could simply replace:

for(int si=menuItem1.MenuItems.Count-1; si>=0;si--)
{
menuItem1.MenuItems.RemoveAt(si);
}

with:

menuItem1.MenuItems.Clear();

-----Original Message-----
I got my menu stuff figured out. I created a main menu with one menu item(menuItem1). When selected, it fills in submenu items and links them to aclick method. On each select, the subitems are cleared out.
I have two more questions

1. When I do the RemoveAt, is the link to the clicker method obliterated?It seems ok. I don't want to keep adding things into the list.2. It there an easier way to do the RemoveAt loop, like in one fell swoop?

private void menuItem1_Select(object sender, System.EventArgs e){
for(int si=menuItem1.MenuItems.Count-1; si>=0;si--)
{
menuItem1.MenuItems.RemoveAt(si);
}

string[] astrWindow= {"111", "222", "333", "444", "555"}; for(int si=0; si<astrWindow.Length;si++)
{
MenuItem filemenu = new MenuItem();
filemenu.Click += new System.EventHandler (this.fmClick); filemenu.Text = astrWindow[si];;
menuItem1.MenuItems.Add(filemenu);
}
}

private void fmClick(object sender, System.EventArgs e)
{
MessageBox.Show(((MenuItem)sender).Text);
}
.

Nov 16 '05 #2

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

Similar topics

1
by: Bizt | last post by:
Hi, I would like to create a menu where the menu options were taken from an XML file. The reason is that I would be able to update the xml file (by simply adding new child nodes) after I...
2
by: pantagruel | last post by:
I have an old web application I did where browsers with dynamic capabilities received a drop down menu on the top of the page and a fold out on the left hand side of the page and non-dynamic...
5
by: Rob Mayo | last post by:
How can I force a MeasureItem message for an owner-dramn menu item? Here is the dilemma. I wrote a lovely little Component for owner-drawing all the menus on a form and making them look like...
2
by: Sisnaz | last post by:
I'm working with 2005 Beta 2 and I'm sure this is a trivial question but for the life of me I can't figure out. I placed a menu navigation componet on my master page and defined the navigation...
7
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote...
4
by: Enrika | last post by:
Greetings! I'm working on a CSS drop-down menu, which, to my surprise, is actually working, more-or-less, in both IE *and* Firefox (and Netscape). But there are two changes that I want to make that...
6
by: roguefeebo | last post by:
Hello everyone, thanks for looking. I'll get right to the point: I'm having problems trying to figure out a hierarchy of menus in C; command-line style. Say, for example the program analyzes a...
7
by: Michael7 | last post by:
Hi everyone, I hope I'm alright in posting this here, I searched and couldn't find any help with this, or even a hint as to where I can ask this. I'm new to SSI and all that . . . actually just...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.