By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Child usercontrol contained parent user control does'nt redisplay

P: n/a
HI All..
I'm realtively new to C#.

I have MainForm which includes Parent usercontol, and this parent
usercontrol also contains child usercontrol.

MainForm --> Parent usercontrol --> child usercontrol

Parent usercontol has one button to change the child usercontorl's
variable.
Child usercontrol has one textbox that display child usercontrol's
variable.

When I press button of parent usercontrol, I change the variabe of
child user control, and I want to display the variable to textbox.
But textbox does not change its value.

What kind of action do I need?
Any suggestion would be greatly appreciated.

oldfark

-----------------Sample Code start----------------
/////////Child usercontorl's code////////////////
public partial class ChildUC : UserControl
{
double val1=0;

public ChildUC()
{
InitializeComponent();
this.textBox1.Text = val1.ToString();
}
public void set_val(double i)
{
val1 = i;
}
}
/////////Parent usercontorl's code/////////////
public partial class ParentUC : UserControl
{
public ParentUC()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.childUC1.set_val(1000);
}
}
///////////// MainForm has deualt code --- no change to original
designer code////////////

------------------------Sample Code end-------------------------------

Jan 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi lotus,
in your set_val method you are assigning the new value to a variable, but
you are not updating the value of the Text property of the textbox which
controls what is displayed in the textbox, you just need to add one more line:

public partial class ChildUC : UserControl
{
double val1=0;

public ChildUC()
{
InitializeComponent();
this.textBox1.Text = val1.ToString();
}
public void set_val(double i)
{
val1 = i;
this.textBox1.Text = val1.ToString();
}
}
Hope that helps
Mark Dawson
http://www.markdawson.org

"lotus" wrote:
HI All..
I'm realtively new to C#.

I have MainForm which includes Parent usercontol, and this parent
usercontrol also contains child usercontrol.

MainForm --> Parent usercontrol --> child usercontrol

Parent usercontol has one button to change the child usercontorl's
variable.
Child usercontrol has one textbox that display child usercontrol's
variable.

When I press button of parent usercontrol, I change the variabe of
child user control, and I want to display the variable to textbox.
But textbox does not change its value.

What kind of action do I need?
Any suggestion would be greatly appreciated.

oldfark

-----------------Sample Code start----------------
/////////Child usercontorl's code////////////////
public partial class ChildUC : UserControl
{
double val1=0;

public ChildUC()
{
InitializeComponent();
this.textBox1.Text = val1.ToString();
}
public void set_val(double i)
{
val1 = i;
}
}
/////////Parent usercontorl's code/////////////
public partial class ParentUC : UserControl
{
public ParentUC()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.childUC1.set_val(1000);
}
}
///////////// MainForm has deualt code --- no change to original
designer code////////////

------------------------Sample Code end-------------------------------

Jan 27 '06 #2

P: n/a
Thanks Mark.

It works fine

oldfark

Jan 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.