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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:05:16+00:00 2026-06-12T20:05:16+00:00

how to give same property to all textboxes present in the same form. foreach

  • 0

how to give same property to all textboxes present in the same form.

      foreach (var textbox in this.Controls.OfType<TextBox>())
        {
            textbox.ContextMenu = new ContextMenu();
        }

The above code works only if the textboxes are not in nested format.

In my project I have multiple tabpages in tabcontrol. so i cant implement the above code. but i can implement the below code:

      foreach (TextBox textbox in this.Controls.OfType<TabControl>().SelectMany(tc => tc.Controls.OfType<TabPage>().SelectMany(page => page.Controls.OfType<TextBox>())))
        {
            textbox.ContextMenu = new ContextMenu();
        }
        foreach (var textbox in this.tabCarInsurance.Controls.OfType<TextBox>())
        {
            textbox.ContextMenu = new ContextMenu();
        }
        foreach (var textbox in this.tabHomeLoans.Controls.OfType<TextBox>())
        {
            textbox.ContextMenu = new ContextMenu();
        }
        foreach (var textbox in this.tabRetirement.Controls.OfType<TextBox>())
        {
            textbox.ContextMenu = new ContextMenu();
        }

Here I am implementing for each tabControl. which still i dont like (because I have more tab pages to take care of). Is there anyway to reduce the above code.

I tried the below code: (not working)

       foreach (var textbox in this.Controls.OfType<TabControl>().OfType<TextBox>())
        {
            textbox.ContextMenu = new ContextMenu();
        }

I got the above code knowledge from my previous question.

Please Help

Thanks in Advance.

  • 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-06-12T20:05:17+00:00Added an answer on June 12, 2026 at 8:05 pm
     private void SetProperty(Control ctr)
        {
            foreach(Control control in ctr.Controls)
            {
                if (control is TextBox)
                {
                    control.ContextMenu = new ContextMenu();               
                }
                else
                {
                    if (control.HasChildren)
                    {
                        SetProperty(control);
                    }                    
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let us guess two objects with same property: var x = {a : 'some'},
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
Both in Actionscript3 and Javascript these statements give the same result: /\S/.test(null) => true
What is the difference? Are these the same? If not, can someone please give
I'm a little bit new to Actionscript, but I can't figure this one out.
Now before people start marking this a dup, I've read all the following, none
Summary Here I'll list all steps I've taken to solve this problem as reference
When you read this you'll be awfully tempted to give advice like this is
I wanted to give all of the child's div elements a background-color of parent
give me suggestion which is related to table view selection action. I have 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.