C# WinForms: Accessing same TextBox control with 2 variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veljkoz
    New Member
    • Feb 2008
    • 3

    C# WinForms: Accessing same TextBox control with 2 variables

    Hi all,

    I have some class that's managing the user interface - CMan, and I'm passing it the struct array with some txtboxes in it. CMan than changes txtboxes.

    This struct is initialized like this:
    Code:
    struct STxt { public TextBox data1; public TextBox data2;};
    STxt [] myArray;
    
    myArray = new STxt[10];
    myArray[0].data1 = txtFirstBox; //txtFirstBox is a TextBox
    myArray[1].data1 = txtSecondBox;
    //...
    
    CMan handler = new CMan(myArray);
    Problem is when I change txt box in CMan it doesn't reflect to myArray, so in the watch screen I have a following situation at the same time:

    Code:
    txtFirstBox.Text = "Sample text";
    handler.TxtArray[0].data1.Text = "Changed text";
    I've eliminated all the typo-errors, and am very puzzled right now... the TextBox isn't a value type, and when I assign it like that to another variable I can use it's properties with both variables (the target should be the same).... right?
    (I guess I can solve it by using unsafe code via pointers, but I'd like to avoid this if possible)
  • veljkoz
    New Member
    • Feb 2008
    • 3

    #2
    Forget about it - it's definitely a typo - I forgot to add property on one assignment (i.e. instead of data1.Text= I wrote data1 =.... it was really freaking me out for 4hrs now....)

    Comment

    Working...