Solved

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

Posted on 2006-11-03
2
279 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

759 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