So, a System.Windows.Forms.Control has a Controls property of type Control.ControlCollection . I have control over a form that contains a bunch of small sub-controls in this collection. These sub-controls have a label and a text identifier, which is the name of the field from the database.
I need to go back to the Controls collection and find the controls by name. ControlCollection has public virtual Control this[string key] { get; } public virtual Control this[string key] { get; } and a public virtual bool ContainsKey(string key) , so it looks like I can find them.
However, the add function ( public virtual void Add(Control value) ) does not accept the key string, just adding System.Windows.Forms.Control , and all my ContainsKey calls return false.
Computing something on Control should be redefined as a key (since only Control is passed), I tried to override ToString() to return the name of the database field (which I want to use for the search), but ContainsKey still returns false when I I know that the control for the specified field is present.
In the documentation for this[string key] { get; } this[string key] { get; } that the key parameter is "The name of the control to retrieve from the control collection." Control does not have a Name property that I can override, its only Name property contains the name of the class, which will be the same for every control that I add. The documentation for ContainsKey(string key) says that the key parameter is “Search Key,” which is even less useful.
Found the answer, but I already wrote all this to publish it, and then answer it myself if someone can find it useful ...
source share