r3nder
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.Help ers.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?
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.Help
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?
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.
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).
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).
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)
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.
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);
Usercontrols.MyUsercontrol
pu.Width = uc.width;
pu.Height = uc.height;
ou.text = "My Title";
pu.Controls.Add(uc);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Bob