PC Review


Reply
Thread Tools Rate Thread

ArgumentException when adding a MenuItem

 
 
INCA Hellas Ltd
Guest
Posts: n/a
 
      17th Nov 2004
Hello,
I am trying to fill a MenuItem of my MainMenu, with the contents of a
ContextMenu which is on another form.
This is supposed to happen when the second form is shown on a panel of the
first.
Also the MenuItem of the MainMenu (called ModMenu) is removed and added as
needed.

So I wrote the following method, however I am getting an argument exception
when I am adding the MenuItem.

public static bool ShowModMenu(Form1 f1,ContextMenu m)

{

f1.Menu.MenuItems.Add(f1.ModMenu);

Menu.MenuItemCollection f1i=f1.ModMenu.MenuItems;

f1i.Clear();

while (m.MenuItems.Count>0)

{

MenuItem mi=m.MenuItems[0];

m.MenuItems.Remove(mi); // I remove the menuitem from the context menu
because the docs say that a menuitem cannot be in two menus at the same time

f1i.Add(mi); // This throws ArgumentException

}

}

Can anybody point out where the problem is?

Thank you in advance,
Konstantinos Tragas
INCA Hellas Ltd.


 
Reply With Quote
 
 
 
 
INCA Hellas Ltd
Guest
Posts: n/a
 
      18th Nov 2004
During debugging I noticed the following:

A MenuItem just constructed has its Parent property set to null.
When it is added to a menu this menu becomes the MenuItem's Parent.
But when it is removed from the menu the Parent does not change back to
null, as I would expect, and I think that this explains the
ArgumentException when I try to add it to another menu.

This seems like a bug to me. Can anybody confirm this?

Thank you
K. Tragas


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ArgumentException when adding a form to a panel =?Utf-8?B?UmVnaXMgRm9udGVz?= Microsoft C# .NET 1 3rd May 2007 08:15 PM
ArgumentException when adding an XML signature =?Utf-8?B?SGFucw==?= Microsoft Dot NET Framework 0 3rd Apr 2006 11:54 AM
Re: ArgumentException when adding to this.Controls Daniel Moth Microsoft Dot NET Compact Framework 0 9th Sep 2005 09:20 PM
Adding to an existing MenuItem's MenuItem Collection Dynamically snesbit Microsoft Dot NET Framework Forms 3 9th Mar 2005 03:08 AM
Adding to an existing MenuItem's MenuItem Collection Dynamically snesbit Microsoft VB .NET 1 9th Mar 2005 03:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:23 PM.