Accessing Controls from a Mediator

mjsnow

Newcomer
Joined
Sep 27, 2003
Messages
13
Hi All,

I have a mediator class that takes a form in its constructor. My question is how I access the controls on the form within the mediator? Using something like frm.txtBox.Text = ""; give a build error. I can move through the controls collection for the reference so the form is there and that part is correct, but I would like to access each control on the form individually in the easiest way possible – something like frm.myTxtBox.Text = “hello”;

Any ideas?

Mike
 
How are you declaring the constructor? If you are passing in a parameter of type Form then you will not get any of the functionality of your specific form, declare the parameter as being the correct type for your form.
 
Hey Plaus,

When I send the form by form name (CompareLists) I get a protection errors when I try to access a given control (...\UI\ListComparisonUIs\CompareListMediator.cs(92): 'UI.ListComparisonUIs.CompareLists.txtBaseList' is inaccessible due to its protection level)

When I send the form by Form, there are no easy ways to access the controls. Of course, they are in the controls collection and I can list them.

Go figure? What am I doing wrong?
 
By default you can't direcly access controls as they are declared as Private (only the class/form itself can access them).
You have to change the Modifier property to internal or public if you want to access them from another class.
 
Thanks Wile for you input. I though of that shortly after I send my last post. I was hoping to find a way to access the controls in a more clean way and not have to modify the form code outside of the form designer. Oh well….
 
Back
Top