Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6924501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:40:16+00:00 2026-05-27T10:40:16+00:00

I have a menu and I am disabling certain options for certain group. It

  • 0

I have a menu and I am disabling certain options for certain group. It is dropdown menu with about 10 entriees. When I run code like this

menuMain.Items[0].ChildItems.RemoveAt(0);
menuMain.Items[0].ChildItems.RemoveAt(1);
menuMain.Items[0].ChildItems.RemoveAt(2);
menuMain.Items[0].ChildItems.RemoveAt(3);
menuMain.Items[0].ChildItems.RemoveAt(4);
menuMain.Items[0].ChildItems.RemoveAt(5);

which means I want to remove first 6 entries for this one group, I get exception at item no 5, saying the index is out of range.

I found the above code removes every other item from menu, not the one that are referenced.

removes 0th item
removes 2nd item
removes 4rd item
...
removes 10th item
removes 12th item (index not found)

Does anyone know why it is behaving like this?

Note: I checked the code in debug mode and it does points to correct menuitem that is both odd and even and it does not jump by 2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:40:16+00:00Added an answer on May 27, 2026 at 10:40 am

    Yes – imagine you initially have items [a, b, c, d, e, f, g, h, i, j, k, l, m].

    Now you call RemoveAt(0). That removes the first item (a), leaving you with [b, c, d, e, f, g, h, i, j, k, l, m].

    Now you call RemoveAt(1). That removes the second remaining item (c), leaving you with [b, d, e, f, g, h, i, j, k, l, m].

    Now you call RemoveAt(2). That removes the third remaining item (e), leaving you with:
    [b, d, f, g, h, i, j, k, l, m].

    … etc

    The problem is that you’re thinking of the indexes in the original list – not after the “removals so far”. If you want to remove the first 6 entries, you can use:

    for (int i = 0; i < 6; i++) {
        menuMain.Items[0].ChildItems.RemoveAt(0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing my custom menu. It behaves like this. I have one toggle button
I have menu designed using jQuery in oracle apex.The menu is like this Parent1
I have menu items with an accelerators. I would like to detect when a
i have menu like this <ul> <li> <a href=#>Home</a> <ul class=sub> <li>Text</li> <li>Test</li> </ul>
I have a menu: <ul> <li id=active><a href=/>Головна</a></li> <li><a href=/about/>Про компанію</a></li> <li><a href=/work/>Діяльність</a></li> <li><a
I have menu generated by a CMS with HTML output like: <ul id=category-nav> <li>
i have menu structure like below, <ul> <li class=menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-1406
I have a dialog application in which I want to have clickable menu items
Have created a ATL COM project through which I am inserting Menu Items to
i have menu structrue like below Testimonials | Photo Credits | Privacy Policy |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.