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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:59:47+00:00 2026-05-24T03:59:47+00:00

So I have a form with some tab objects, group objects and possible a

  • 0

So I have a form with some tab objects, group objects and possible a table layout pannel inside of a group object.

Based on data locks the form will disable almost all of its content so I need to mark things as read only so the users can still see the data but not change it…

Here is the code I have to dive through collections and mark objects as read only…

    private void lockForm()
    {
        btnLockData.BackColor = Color.LightBlue;
        btnLockData.Text = "Data locked!  Click to unlock...";

        foreach (Control formObject in this.Controls)
        {
            if (formObject is TabControl)
            {
                foreach (Control tabControl in (formObject.Controls))
                {
                    foreach (Control tabPageObject in (tabControl.Controls))
                    {
                        if (tabPageObject is TextBox)
                            ((TextBox)tabPageObject).ReadOnly = true;

                        if (tabPageObject is DataGridView)
                            ((DataGridView)tabPageObject).ReadOnly = true;


                        if (tabPageObject is GroupBox)
                        {
                            foreach (Control groupBoxObject in tabPageObject.Controls)
                            {
                                if (groupBoxObject is TextBox)
                                    ((TextBox)groupBoxObject).ReadOnly = true;

                                if (groupBoxObject is DataGridView)
                                    ((DataGridView)groupBoxObject).ReadOnly = true;

                                if (groupBoxObject is TableLayoutPanel)
                                {
                                    foreach (Control layoutObject in groupBoxObject.Controls)
                                    {
                                        if (layoutObject is TextBox)
                                            ((TextBox)layoutObject).ReadOnly = true;

                                        if (layoutObject is DataGridView)
                                            ((DataGridView)layoutObject).ReadOnly = true;                                            
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        dgvResources.ReadOnly = false;
        dgvDirectLabor.ReadOnly = false;
    }

Is there a better way to control this behavior?

  • 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-24T03:59:48+00:00Added an answer on May 24, 2026 at 3:59 am

    For more granular control of which controls to set Readonly try:

       this.Controls.Cast<Control>()
            .Where(ctl => ctl is TextBox).Cast<TextBox>().ToList()
            .ForEach(e => e.ReadOnly = true);
    
        this.Controls.Cast<Control>()
            .Where(ctl => ctl is DataGridView).Cast<DataGridView>().ToList()
            .ForEach(e => e.ReadOnly = true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a bunch of panels, and some panels inside groupboxes.
I apologize in advance, I am a PHP noob! I have form with some
I have a form with some radio buttons that are disabled by default. When
I have a form with some controls. (Actually, this is a sort of ongoing
i have a form with some checkboxes on it i want to save those
I have a form with some input texts passed in GET, and i don't
Please help! I have some form elements in a div on a page: <div
I am working on zend. I have a form with some checkboxes. I want
Using ASP.NET VB, I have a form with some text boxes and a Gridview.
I have subclassed Form to include some extra functionality, which boils down to a

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.