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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:07:27+00:00 2026-05-27T21:07:27+00:00

So, a System.Windows.Forms.Control has a Controls property of type Control.ControlCollection . I have a

  • 0

So, a System.Windows.Forms.Control has a Controls property of type Control.ControlCollection. I have a control on a form that has a bunch of small sub-controls in this collection. These sub-controls have a label and a text identifier that’s the field name from a database.

I need to be able to go back into the Controls collection and find the controls by name. ControlCollection has a public virtual Control this[string key] { get; } and a public virtual bool ContainsKey(string key), so it looks like I should be able to look them up.

However, the Add function (public virtual void Add(Control value)) doesn’t take a key string, just the System.Windows.Forms.Control you’re adding, and all my calls to ContainsKey are returning false.

Figuring something on the Control has to be overridden to be the key (since only the Control is passed), I tried overriding ToString() to return the database field name (which I’m wanting to use for the lookup), but ContainsKey still returns false when I know a control for the field specified is present.

The documentation for this[string key] { get; } says the key parameter is “The name of the control to retrieve from the control collection.” The Control does not have a Name property I can override, its only Name property contains the class name, which will be the same for every control I’m adding. The documentation for ContainsKey(string key) says the key parameter is “The key to locate”, which is even less helpful.

Found the answer, but I already wrote all this up so I might as well publish it and then self-answer in case someone else might find it useful…

  • 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-27T21:07:28+00:00Added an answer on May 27, 2026 at 9:07 pm

    While I can’t override the Name property, it’s {get;set;}, not pure {get;} as I stupidly assumed. So if I set the Name of my control to the database field name before I add it to the Controls collection, I can look it up as expected.

    The answer was in the summary docs of the Control[] Find(string key, bool searchAllChildren) method, not the docs for the functions I was going to use:
    “Searches for controls by their System.Windows.Forms.Control.Name property and builds an array of all the controls that match.”

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

Sidebar

Related Questions

My WinForms application has a tab with a System.Windows.Forms.WebBrowser control. There are several controls
I have written a control in C# that derives from System.Windows.Forms.Control. I have added
I have a Windows Forms project. For some controls the property Image has value
I have a custom control that I made. It inherits from System.Windows.Forms.Control , and
I have a windows forms project. It has a main form derived from System::Windows::Forms::Form
I have a custom control: it's managed code, which subclasses System.Windows.Forms.Control. I want to
I have a System.Windows.Forms.Button control, and I want to add a hover-text explanation of
How can I detect when a System.Windows.Forms.WebBrowser control has completed loading? I tried to
I have a control derived from System.Windows.Forms.UserControl which is placed in a customized grid.
I have a control (derived from System.Windows.Forms.Control) which needs to be transparent in some

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.