Solved

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

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 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