0
public partial class A : UserControl
{
  private string _x;
  public string X {
    get { return _x; }
    set { 
      this._x = value;
      this.textBox1.Text = this._x; 
  }
}
public partial class B : WinForm
{
   public B() {
     //Add usercontrol A to Groupbox1
     //Set A.X = "hello world"
   }
}
public class MainForm: WinForm
{
    public void button1_Click(....) { 
       B bForm = new B();
       bForm.ShowDialog();
    }
}

At design time, I set the textbox1.Text="hello". In the Main Class, I have a button that will open a new form B and on that form B I have a group box to add this user control A and change the X property value = "hello world" but the textBox1.Text doesn't change on the UI. When I set break point after the set textbox1.Text = this._x, it shows the value did change to "hello world" but it's not reflected on the UI?

Why? And how to fix it?

Thanks a bunch.

9
  • 2
    Do you want to change the text of textbox same as the X than you have to assign this.txtBox1.Text = this._x; Commented Feb 15, 2013 at 6:29
  • Do you use dataBinding? Commented Feb 15, 2013 at 6:38
  • No, I don't use databinding. Wonder why the set .Text directly doesn't work. Commented Feb 15, 2013 at 6:40
  • @user858931 Show your ` //Show Form B` code Commented Feb 15, 2013 at 6:53
  • @nikita I just updated it. Commented Feb 15, 2013 at 6:58

1 Answer 1

3

My guess is (since I don't see all code and it's all like guessing game 8)) - there is InitializeComponent method in classB. Since X property doesn't have DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) attribute it is serialized in InitializeComponent method with empty string - thus erasing previously explicitly set value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.