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 7034195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:09:23+00:00 2026-05-28T01:09:23+00:00

I’m trying to create a context menu which will be able to add extra

  • 0

I’m trying to create a context menu which will be able to add extra menu items, with an attached child menu, as required. I’ve been trying to do it so I have separate classes building up each part so it can be written nicely with objects.

The problem I am having is that the AddRange method for ContextMenuStrip doesn’t have a constructor to deal with my object. I’ve tried converting it to ToolStripMenuItem type with operators which has not worked, as I suspected it wouldn’t.

I am sure this can be achieved so I assume I’ve thought something through wrong. Is there a way to get around this or I banning my head against a wall with my current structuring?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Context
{
class TestMenu
{
    public TestMenu()
    {
        ContextMenuStrip filesToUploadContext = new System.Windows.Forms.ContextMenuStrip();

        // Hot Folder Header
        ToolStripMenuItem hotHead = new System.Windows.Forms.ToolStripMenuItem();
        // Holder for files in Hot Folder
        ParentItem hotFile; // foreach

        // Dropped Files Header
        ToolStripMenuItem dropHead = new System.Windows.Forms.ToolStripMenuItem();
        // Holder for files that have been dragged and dropped in
        ParentItem dropFile; // foreach

        ToolStripSeparator toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
        ToolStripSeparator toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();

        filesToUploadContext.Items.AddRange(new ToolStripItem[] {
            hotHead,
            toolStripSeparator1,
            hotFile, // Not a toolStrip item

            dropHead,
            toolStripSeparator2,
            dropFile // also not a toolStrip item
            });

        //// Testing stuff vv
        //// Hot Folder
        //hotFile.DropDownItems.AddRange(new ToolStripItem[]
        //    {
        //        viewHot,
        //        deleteHotFile
        //    });

        //// Dropped Items Folder
        //dropFile.DropDownItems.AddRange(new ToolStripItem[]
        //    {
        //        viewDrop,
        //        removeDropFile
        //    });

        //// Hot Folder Section Heading
        //hotHead.Name = "hotHead";
        //hotHead.Text = "Hot Folder Files";
        //hotHead.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);

        //// Drop Folder Section Heading
        //dropHead.Name = "dropHead";
        //dropHead.Text = "Dropped Files";
        //dropHead.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
    }

    class ParentItem
    {
        // MenuItem to be used for found files
        // Options will contain child items
        public ToolStripMenuItem name = new ToolStripMenuItem();
        public ChildMenu options { get; set; }
        public ParentItem();
    }

    class ChildMenu
    {
        // Options available for specific files at end of menu tree
        public ToolStripMenuItem view = new ToolStripMenuItem("View File");
        public ToolStripMenuItem delete = new ToolStripMenuItem("Delete File");
        public ToolStripMenuItem remove = new ToolStripMenuItem("Remove File");
        public ChildMenu();
    }

}

}

  • 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-28T01:09:24+00:00Added an answer on May 28, 2026 at 1:09 am

    You can’t add anything else than a ToolStripMenuItem as child of a ToolStripMenuItem.

    Don’t spend time trying to inherit your ChildMenu and ParentItem classes from ToolStripMenuItem. Just add ToolStripMenuItems and drop these classes.

    EDIT:

    I would do something like the following (actually compiles):

    public void PopulateMenu(string fileName, ContextMenuStrip parent)
        {
            ToolStripMenuItem newMenu = new ToolStripMenuItem(fileName);
            newMenu.DropDownItems.Add(new ToolStripMenuItem("View File"));
            newMenu.DropDownItems.Add(new ToolStripMenuItem("Delete File"));
            newMenu.DropDownItems.Add(new ToolStripMenuItem("Remove File"));
    
            parent.Items.Add(newMenu);
        }
    

    Then for each of your file:

    this.PopulateMenu(the_file_name, the_parent_menu);
    

    Also don’t forget to attach handlers to the Click event of your menus, or they’ll be useless 😉

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

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.