Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-11-03
2
Medium Priority
?
282 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 1500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

664 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