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

  • SEARCH
  • Home
  • 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 6038671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:15:22+00:00 2026-05-23T06:15:22+00:00

I have a large list of entities which the user needs to be able

  • 0

I have a large list of entities which the user needs to be able to select from.
I have a ContextMenuStrip on my window, and has a few MenuItems for each category of entity.

In a library example, think “Staff”, “Borrowables”, “Patrons”, etc…

“Staff” may contain “By Employment Type” -> { “Full Time”, “Part Time” } or “By Gender” -> { “Male”, “Female” } etc.

“Borrowables” may contain “By Type” -> { “Books”, “Magazines”, “DVDs” } or “By Genre” -> { “Fiction” -> { “Sci-Fi”, “Romance”, “Crime” }, “Non-Fiction” { “Science”, “Music”, “History” } } etc.

Basically, one entity can be in several places at once. A staff member can be full time, and female. A borrowable might be a book, and a romance novel. etc.

I have programatically created a List<ToolStripMenuItem> together with event handlers, tags, everything. I have then programatically gone through each of them and added them to various menus and sub-menus so that they can be accessed from a variety of places. The idea is that I only need 1 object in memory per ToolStripMenuItem, and if it’s checked/unchecked then that should be reflected on all of them.

This would seem to be an elegant solution, and I was really looking forward to seeing it work, but apparently when I add a ToolStripMenuItem to one ToolStripMenuItemDropDownItems, it gets removed from wherever else it was added.

This makes me sad. If they were all the same object, I wouldn’t have to write a lot of code to go through and check all matching items when one is checked, because checking one would check them all, and unchecking one would uncheck them all.

Is there any other way I can accomplish this with minimal code?

This is a small example of what I have:

foreach (ToolStripMenuItem item in staffItems)
{
  Staff s = (Staff)item.Tag;

  foreach (ToolStripMenuItem tsmi in byStaffLocationToolStripMenuItem.DropDownItems)
    if ((Location)tsmi.Tag == s.Location)
      tsmi.DropDownItems.Add(item); // [1] Item added here

  foreach (ToolStripMenuItem tsmi in byStaffTypeToolStripMenuItem.DropDownItems)
    if ((StaffType)tsmi.Tag == s.StaffType)
      tsmi.DropDownItems.Add(item); // removed from [1] and added here instead :(
}
  • 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-23T06:15:23+00:00Added an answer on May 23, 2026 at 6:15 am

    That’s the feature of the ControlCollection. Any object derived from Control can be only in one ControlCollection at the same time.

    If you want to follow your approach I suggest (draft) introducing abstraction for your command:

    public interface ICommand
    {
        string Name {get;set;}
        bool Enabled { get; set; }
        bool Checked { get; set; }
    
        void OnClick();
    }
    

    Then you can create your own class which will derive from ToolStripMenuItem and take ICommand as a parameter and use it OnClick. Now you should be able to define single object implementing ICommand for a single command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large list of email addresses, and I need to determine which
I have a large list of Users in an NSDictionary that has a structure
I have a large list(over 1,000,000 items), which contains english words: tokens = [today,
I have a large list of <li> 's that are given a width from
I'm have a large list of value types that needs to be given to
i have a large list of static data from a server that i load
I have a large list (~ 110,000 strings), which I need to compare to
I have got this large list of names here http://projecteuler.net/project/names.txt , which I am
I have a large list [[1,.., ..],[2,...,...],[5,...,...],[1,...,...]] I need to remove all elements that
I have a large list of file names that are illegal, I want to

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.