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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:14:48+00:00 2026-05-18T08:14:48+00:00

I am trying to get the same functionality that a combobox has, like combobox1.Items.Add()

  • 0

I am trying to get the same functionality that a combobox has, like combobox1.Items.Add() // editor.Tags.Tags1()

Like this:

class Main()
{
    // The editor is passed into the editor class, that allows the editor class to update the editor.
    MyEditorClass editor = new MyEditorClass(editorBox);
    editor.Tags.InsertTag1();

    // Now i don't want people to do this
    // MyEditorClass.TagClass tags = new MyEditorClass.TagClass();
}

The reason is that the tags class calls the editorBox passed into the MyEditorClass and if you create a tags class without that editor, it won’t work.

My MyEditorClass looks like this:

public class MyEditorClass
{
    static RichTextBox editor;
    public TagClass Tags;

    public MyEditorClass(RichTextBox editorBox)
    {
        editor = editorBox;
        Tags = new TagClass();
    }



    public class TagClass
    {
        public void InsertTag1()
        {
            editor.Text += "Test tag 1";
        }
    }
}

I was trying to make the TagClass static but that didn’t work. How is the combobox structured? Since you cant use Combobox.Items but if you declare one you can use the Combobox.Items on the one that you declared.

  • 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-18T08:14:49+00:00Added an answer on May 18, 2026 at 8:14 am

    Make your Tags property readonly, then it can be initialized in the constructor only:

    public readonly TagClass Tags;
    

    The object reference stored in Tags can’t be changed later then and that code:

    MyEditorClass editor = new MyEditorClass(editorBox);
    editor.Tags = new MyEditorClass.TagClass();
    

    wouldn’t compile.

    Or, second possibility, even better – expose only public getter for your Tags property and keep the instance privately inside your MyEditorClass class, like in example below.

    By the way, it don’t have to do anything with nesting classes. It is quite strange to have public class inside a public class.


    EDIT:
    To have a structure similar to ComboBox so that TagClass has access to the editor, you can pass the editor instance to TagClass internal constructor. The constructor is internal to not allow external code to use TagClass directly.

    public class MyEditorClass
    {
        private readonly RichTextBox editor;
        private readonly TagClass tags;
    
        public TagClass Tags
        {
            get 
            {
                return tags; 
            } 
        }
    
        public MyEditorClass(RichTextBox editorBox)
        {
            editor = editorBox;
            tags = new TagClass(editorBox);
        }
    }
    
    public class TagClass
    {
        private RichTextBox _editor;
    
        internal TagClass(RichTextBox editor)
        {
            _editor = editor;
        }
    
        public void InsertTag1()
        {
            _editor.Text += "Test tag 1";
        }
     }
    

    And now this will work:

    MyEditorClass editor = new MyEditorClass(editorBox);
    editor.Tags.InsertTag1();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get my css / C# functions to look like this: body {
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Just trying to get my head around Generics by reading this enlightening article by
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get an ASP application deployed; it worked for a while but then
Whilst trying to get our app working in Firefox (I'm a big proponent of
Im trying to get into some basic JavaFX game development and I'm getting confused
Im trying to get a completly data copy from a gridview, itryed clone(), tryed
Just trying to get my irb sessions to actually list the current line of
Just trying to get up to speed with the SDK... So, I've created my

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.