mjsnow Posted December 2, 2004 Posted December 2, 2004 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 Quote
Administrators PlausiblyDamp Posted December 2, 2004 Administrators Posted December 2, 2004 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mjsnow Posted December 2, 2004 Author Posted December 2, 2004 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? Quote
Wile Posted December 2, 2004 Posted December 2, 2004 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. Quote Nothing is as illusive as 'the last bug'.
mjsnow Posted December 3, 2004 Author Posted December 3, 2004 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�. Quote
Administrators PlausiblyDamp Posted December 3, 2004 Administrators Posted December 3, 2004 You could always create public methods / properties as wrappers around the form's controls. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.