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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:35:35+00:00 2026-05-21T10:35:35+00:00

I have a hidden control which contains a textbox control and I want to

  • 0

I have a hidden control which contains a textbox control and I want to set the text property of the textbox but i get an NullReferenceException. However if I show the control, set the value and then hide it then i get no exception.

miStatus1.Show();
miStatus1.ioItem1.popIoItem(caseState); 
miStatus1.Hide();

However this feels like a really unclean and not very elegant way to do it. And i’m seeing some flickering because i have to do this to 4 controls with up to 8 textboxes on each.

Is there any way to set the text propery of the textboxes while the control is hidden? Or is it perhaps a better idea to populate my textboxes when showing the control? And will this slow down my application as it needs to populate everytime the control is shown?

popIoItem – code

public void popIoItem(object obj){

            if (ioType == 1)
            {
                tb.Text = (string)obj;
            }
        }

My interface

I’m trying to create the menu to the right and on each pressing of the categories the menus slide up/down and i hide/show the proper user control with the textboxes and other io-elements.

Interface: it is the menu to the right i'm trying to create

More code

When one of the boxes to the left is click’ed the following method is run:

public void openMenu(int caseNum)
        {

            caseDB.casesDataTable chosenCase;
            chosenCase = _casesAdapter.GetDataByID(caseNum);

            string caseName = "";
            int caseOwner = -1;
            DateTime caseDate = DateTime.Today;
            string caseDesc = "";
            int caseState = -1;

            foreach (caseDB.casesRow casesRow in chosenCase)
            {
                if (!casesRow.IscaseNameNull())
                    caseName = casesRow.caseName;

                if (!casesRow.IscaseCreatedByNull())
                    caseOwner = casesRow.caseCreatedBy;

                if (!casesRow.IscaseCreatedNull())
                    caseDate = casesRow.caseCreated;

                if (!casesRow.IscaseDescNull())
                    caseDesc = casesRow.caseDesc;

                if (!casesRow.IscaseStateNull())
                    caseState = casesRow.caseState;

            }


            int caseJobs = (int)_jobsAdapter.JobCount(caseNum);

            string caseStateStr = Enum.GetName(typeof(caseState), caseState);



            caseInfoMenu1.popMenu(caseName, caseOwner, caseDate, caseDesc,caseJobs,caseStateStr);

        }

The caseInfoMenu is the right menu. It consists of some drawing and mouse logic that draws the menu and handles hit-detection. Besides this it contains 4 user controls, one for each of the vertical tabs.

public void popMenu(string caseName, int caseOwner ,DateTime caseDate, string caseDesc, int caseJobs, string caseState)
        {
            marked = 0;

            miGeneral1.Show();
            miEconomy1.Hide();
            miStatus1.Hide();
            miHistory1.Hide();

            miGeneral1.ioItem1.popIoItem(caseName);
            miGeneral1.ioItem2.popIoItem(caseOwner.ToString());
            miGeneral1.ioItem3.popIoItem(caseDate.ToShortDateString());
            miGeneral1.ioItem4.popIoItem(caseJobs.ToString());
            miGeneral1.ioItem5.popIoItem(caseDesc.ToString());

            //miStatus1.ioItem1.popIoItem(caseState);
            //This is commented out because it makes the application crash. However if I show miStatus1, set the value and hide it, it does not crash. 

            this.Invalidate();



        }

Inside each of these user controls I have io-items user controls which essentially draws a blue box and puts a control in front of if ie. the textbox.

public partial class ioItem : UserControl
    {
        public int ioType { get; set; }
        public int ioPadding { get; set; }

        RichTextBox tb;



        public ioItem()
        {
            InitializeComponent();

        }

        public void popIoItem(object obj){

            if (ioType == 1)
            {
                tb.Text = (string)obj;
            }
        }

        private void ioItem_Load(object sender, EventArgs e)
        {
            switch (ioType)
            {

                case 1:

                    tb = new RichTextBox();
                    tb.Location = new System.Drawing.Point(ioPadding, ioPadding);
                    tb.Name = "textbox";
                    tb.Size = new Size(this.Size.Width - (ioPadding * 2), this.Size.Height - (ioPadding * 2));
                    tb.BorderStyle = BorderStyle.None;
                    tb.Visible = true;
                    tb.BackColor = Color.FromArgb(255, 184, 198, 208);
                    tb.Font = new Font("Microsoft Sans Serif", 7);

                    this.Controls.Add(tb);
                    break;


                case 2:

                    historyCtrl hiCtrl = new historyCtrl();
                    hiCtrl.Location = new Point(0,0);
                    hiCtrl.Size = new Size(this.Width, this.Height);
                    hiCtrl.Name = "history";
                    hiCtrl.Visible = true;
                    hiCtrl.BackColor = Color.FromArgb(255, 184, 198, 208);

                    this.Controls.Add(hiCtrl);

                    break;

                default:
                    goto case 1;


            }


        }
    }
  • 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-21T10:35:35+00:00Added an answer on May 21, 2026 at 10:35 am

    So i figured out what was wrong. The problem was something else than what I initially expected. The reason why it didn’t work was because I created my textbox controls in the Load_event. When I tried to set the value of the text property of the textbox controls they hadn’t been created yet. The reason why I had created the user controls containing the textboxes this way was in order to make it easy to drag them into the screen in the Designer. I found this discussion 'UserControl' constructor with parameters in C#, which showed me another way of doing it and now it works.

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

Sidebar

Related Questions

Here's the situation: I have a custom TextBox control that contains multiple other TextBox
I have page which is desgined for map point browsing. I want to show
I use overflow: hidden on my site to get control over ending floats. Which
I have a control that has Hidden visibility because it is bound to a
I currently have a control that is being hidden on my server side using
We have hidden the status bar in our application. But when there is an
I have a hidden div which I reveal with the jquery fadein() method: $(#panel).fadeIn(slow);
I have a hidden input field on a page <div id=SomeDiv> <input type=text name=ID
I have a UIView which contains some controls (e.g. buttons, labels, etc). I overlay
I have a form which contains a whole bunch of checkboxes and some other

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.