Solved

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

Posted on 2006-11-03
2
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

622 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