Thanks to help in here I’ve managed to recursively loop through all the controls on my winform and locate my sub classed control but when I try to update my user defined properties _key and _value the object ctrl does not expose them 🙁
I’m using
ctrlContainer below is the calling form passed as this
foreach (Control ctrl in ctrlContainer.Controls)
{
// code to find my specific sub classed textBox
// found my control
// now update my new property _key
ctrl._key does not exist :(
I know the ctrl exists and is valid because ctrl.Text = "I've just added this text" works.
_key is visible when looking at the control in the form designer.
}
Can anyone give me a hint as to what I’m doing wrong?
Thanks.
That is because your reference is of type
Control(foreach (Control ctrl), which I’m assuming is not your sub-classed control. That reference will only understand members that belong to it,_keypresumably belongs to a derived class. Try this:Or your can change your iterator to find only instances of your control, as suggested by Sebastian. This would be cleaner code.