471,325 Members | 1,233 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Child usercontrol contained parent user control does'nt redisplay

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
2 2191
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
Thanks Mark.

It works fine

oldfark

Jan 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by ian justice | last post: by
10 posts views Thread by Nick L | last post: by
1 post views Thread by Danny Ni | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.