Solved

Why am I getting out of range exception with these code?

Posted on 2006-11-03
2
274 Views
Last Modified: 2008-01-09
Hi:  Below is the error I got from the 2 lines of code below.  I don't understand why and how to correct it.  The actionMenu.DropDownItems has 0 item in its collection at the time of the code.  Thanks.

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.


                        ToolStripItemCollection contextsMenuItems = contextsMenuStrip.Items;
                        .AddRange(contextsMenuItems);
0
Comment
Question by:lapucca
2 Comments
 
LVL 6

Accepted Solution

by:
so3 earned 500 total points
ID: 17872632
Make sure not to use the same contextmenu to add it, like below:

ToolStripItemCollection contextsMenuItems = contextsMenuStrip.Items;
contextsMenuStrip.AddRange(contextsMenuItems);


Show the whole code lines to see it. Normally this shouldn't  get an error if you use 2 contextmenu
0
 
LVL 8

Expert Comment

by:sabeesh
ID: 17878801
You should consider the index of a contextmenustrip
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now