Link to home
Start Free TrialLog in
Avatar of r3nder
r3nderFlag for United States of America

asked on

Accessing variables instantiated by parent usercontrol

I have a form and 2 usercontrols
The form is just a container for the main user control.
The main usercontrol is basically just a tab control
In the codebehind for that usercontrol I have newed up a class
called DTOV  - so in this class I have  public UserControls.SureFire.Helpers.DTOV dtov = new Helpers.DTOV();
and I have a variable in that class called
public int IHaveUnclaimed {get;set;}
---------
In the Main usercontrol I have set that variable with a value and I want to access it in a child user control that is on a tab in the main usercontrol - how can I do that.  - I want to be able to access dtov.IHaveunclaimed
Is that possible?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

You have tags for Winforms, but the description sounds like a web site issue, so I am confused.  The proper solution depends on the answer.
Avatar of r3nder

ASKER

Winforms
1) Is there a reason to split up the form into separate controls?  In my opinion, that just creates a level of complexity, and makes it more difficult to maintain the code.

2) You would need to get a reference to the parent control, in order to access the property.  You should be able to do that with the Parent property (it's been a while since I have worked with Windows Forms).
Avatar of r3nder

ASKER

I tried Form parent = (Form) this.parent;
but that didny wprk
parent was null (event though it is just a usercontrol and not a form)
How are you adding the user control to the form?  You might need to set Parent explicitly.
Avatar of r3nder

ASKER

forms.Popup pu = new popup();
Usercontrols.MyUsercontrol uc = new MyUsercontrol();
pu.Width = uc.width;
pu.Height = uc.height;
ou.text = "My Title";
pu.Controls.Add(uc);
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r3nder

ASKER

Thanks Bob