473,698 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing Context Menu Items

I have an Windows app that allows users to save "bookmarks" , on pages they
have been to, and then navigate back to them. That all works. In addition, we
have restricted them to 15 bookmarks, and if they select a 16th, the first
one in is popped out. I am attaching a Context Menu to a button on the
toolbar.

Now they would like to be able to delete an individual bookmark. I have the
code working to dynamically add the bookmarked pages, to a sub-menu item for
deletes. I even have the code working to delete the item from that MeunItems
collection. When I check the count of that collection, it is correct, and
when I click my code to add another bookmark, the old ones appear, and the
one I deleted is gone. HOWEVER, when I go through the delete code, and then
click on the button, none of the entries appear. The sub-menu for the deletes
is blank. Here's the code:

Load the Menu Items, both in the Main menu and the Delete Bookmarks

private void button1_Click(o bject sender, System.EventArg s e)
{
for (int i = 0; i < 6; i++)
{
MenuItem myMenuItem =
mainToolBar.But tons[0].DropDownMenu.M enuItems.Add("A dded Item " + i);
this.mainToolBa r.Buttons[0].DropDownMenu.M enuItems[myMenuItem.Inde x].Click
+= new System.EventHan dler(AnotherMen uTestMethod);
deleteBookmarkM enuItem.MenuIte ms.Add(myMenuIt em.CloneMenu()) ;

deleteBookmarkM enuItem.MenuIte ms[deleteBookmarkM enuItem.MenuIte ms.Count
-1].Click -= new System.EventHan dler(AnotherMen uTestMethod);
deleteBookmarkM enuItem.MenuIte ms[deleteBookmarkM enuItem.MenuIte ms.Count
-1].Click += new System.EventHan dler(DeleteMenu TestMethod);
}
}

Here I'm trying to delete a specific one (just to see how to do it)

public void DeleteMenuTestM ethod(object sender, System.EventArg s e)
{
MenuItem myMenuItem = (MenuItem)sende r;
deleteBookmarkM enuItem.MenuIte ms.RemoveAt(3);

MessageBox.Show (deleteBookmark MenuItem.MenuIt ems.Count.ToStr ing());
}

As I mentioned the count is right, but when I click on the button, NOTHING
appears in the Delete Items.

By the way the 'deleteBookMark MenuItem' variable is a global one for the
form.

I'm obviously missing something, anyone spot it?

THANKS!

WhiteWizard (aka Gandalf)
May 2 '06 #1
3 2025
As it turns out, it appears this is a "bug" in .NET 2003, and has been fixed
in 2005. I took the code as is into VS 2005 and it works fine. As we are
moving there in the next month or so, I guess I'll just wait to finish this
then.

WhiteWizard (aka Gandalf)
MCSD.NET, MCAD, MCT
"WhiteWizar d" wrote:
I have an Windows app that allows users to save "bookmarks" , on pages they
have been to, and then navigate back to them. That all works. In addition, we
have restricted them to 15 bookmarks, and if they select a 16th, the first
one in is popped out. I am attaching a Context Menu to a button on the
toolbar.

Now they would like to be able to delete an individual bookmark. I have the
code working to dynamically add the bookmarked pages, to a sub-menu item for
deletes. I even have the code working to delete the item from that MeunItems
collection. When I check the count of that collection, it is correct, and
when I click my code to add another bookmark, the old ones appear, and the
one I deleted is gone. HOWEVER, when I go through the delete code, and then
click on the button, none of the entries appear. The sub-menu for the deletes
is blank. Here's the code:

Load the Menu Items, both in the Main menu and the Delete Bookmarks

private void button1_Click(o bject sender, System.EventArg s e)
{
for (int i = 0; i < 6; i++)
{
MenuItem myMenuItem =
mainToolBar.But tons[0].DropDownMenu.M enuItems.Add("A dded Item " + i);
this.mainToolBa r.Buttons[0].DropDownMenu.M enuItems[myMenuItem.Inde x].Click
+= new System.EventHan dler(AnotherMen uTestMethod);
deleteBookmarkM enuItem.MenuIte ms.Add(myMenuIt em.CloneMenu()) ;

deleteBookmarkM enuItem.MenuIte ms[deleteBookmarkM enuItem.MenuIte ms.Count
-1].Click -= new System.EventHan dler(AnotherMen uTestMethod);
deleteBookmarkM enuItem.MenuIte ms[deleteBookmarkM enuItem.MenuIte ms.Count
-1].Click += new System.EventHan dler(DeleteMenu TestMethod);
}
}

Here I'm trying to delete a specific one (just to see how to do it)

public void DeleteMenuTestM ethod(object sender, System.EventArg s e)
{
MenuItem myMenuItem = (MenuItem)sende r;
deleteBookmarkM enuItem.MenuIte ms.RemoveAt(3);

MessageBox.Show (deleteBookmark MenuItem.MenuIt ems.Count.ToStr ing());
}

As I mentioned the count is right, but when I click on the button, NOTHING
appears in the Delete Items.

By the way the 'deleteBookMark MenuItem' variable is a global one for the
form.

I'm obviously missing something, anyone spot it?

THANKS!

WhiteWizard (aka Gandalf)

May 2 '06 #2

WhiteWizard wrote:
As it turns out, it appears this is a "bug" in .NET 2003, and has been fixed
in 2005. I took the code as is into VS 2005 and it works fine. As we are
moving there in the next month or so, I guess I'll just wait to finish this
then.


I thought it might be that. My investigation had got as far as noticing
that deleteBookmarkM enuItem's .Handle was changing, suggesting the
win32 menu was being recreated on a whim, but I couldn't pin it down
any further.

Is there an online reference to this bug?

--
Larry Lard
Replies to group please

May 2 '06 #3
I did not find an online reference to the bug. I had just decided to see if
I got the same reaction in 2005, and turns out it runs fine there.

Thanks for trying.

WhiteWizard (aka Gandalf)
MCSD.NET, MCAD, MCT
"Larry Lard" wrote:

WhiteWizard wrote:
As it turns out, it appears this is a "bug" in .NET 2003, and has been fixed
in 2005. I took the code as is into VS 2005 and it works fine. As we are
moving there in the next month or so, I guess I'll just wait to finish this
then.


I thought it might be that. My investigation had got as far as noticing
that deleteBookmarkM enuItem's .Handle was changing, suggesting the
win32 menu was being recreated on a whim, but I couldn't pin it down
any further.

Is there an online reference to this bug?

--
Larry Lard
Replies to group please

May 2 '06 #4

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

Similar topics

4
3058
by: Mohit Gupta | last post by:
Hi all, Lately I have been working on an application in VB .net CF for Pocket PC device. I have a small question about Context Menu. When I try to close the window after context menu is poped up, the window does not closes until I click on the window. Below is the code. Hopefully, you can help me out.
8
10097
by: Dennis C. Drumm | last post by:
Is there a way to modify the standard context menu shown when someone right clicks in a windows text box and that would work for all open windows applications? The standard context menu for a text box has 6 items, undo, cut, copy, paste, delete and select all. I would like to add one additional paste menu that opens a new sub menu with several optional text items that could be pasted. The items would be populated by my program but...
0
1569
by: VP | last post by:
G'day folks, well i am attempting to get an understanding on how to create the menuitems in a context menu on the fly. So far I have managed to actually achieve the menu items being created for the context menu. However, I have stumbled across one problem. Which is that how does one go about enhancing the event handler for the context menu to invoke individual actions for each of the menu items. I have included a snippet of my code....
5
2703
by: yxq | last post by:
Hi I am build vb6 Context menu extension, but how to determine which popup menu item(popupItem1 and popupItem2) was clicked? Thanks The code ' ' IContextMenu::QueryContextMenu '
1
6337
by: goRide | last post by:
Hi, I'm looking of a way (preferred - a ready class or dll) to customize the context menu. many application has more controls inside the context menu (like textbox, sliders, checkbox, panel etc'). is there a way making this without writing my own context menu (meaning, popup form or something) ? Please don't post commercial products to this topic thanks.
5
10082
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException because the ListView seems to be trying to "re-select" items that are no longer there! for example, giventhat I have 3 items in my list: Select the first and remove it - no problem.
2
5906
by: MCM | last post by:
I'm working on a plotting control. The plotting control will have a context menu with basic commands for "scaling", "zooming", etc. Is there a way that, from the parent form, I can add more commands to the control's context menu? I'm envisioning a case where the control has a set of context menu items, and the parent form also has a set of context menu items. Thanks.
2
2268
by: parez | last post by:
Hi, I build the menu strip using the designer.I want the context menu of the form to be same as the of children of one of the top leven Menu strip item. Items gives me a ToolStripItem object but it does not have a hierarchy, no parents no children.
1
5591
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got one Context Menu named mi_EasterEggs with three (3) menu items: * mi_FontArial * mi_FontCourier * mi_RawData All menu items have their Visible properties set to False when the form loads. This context menu is included in one (1) ListView control and one (1) TextBox control.
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7734
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6524
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.