#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    84
    Rep Power
    6

    Writing to textbox issue from another class


    Hi there Guru's,

    I have a form with a property that writes to a textbox; I call this property from a function within another class, and when the new value is assigned to the textbox (stepping through confirms the data is there) nothing happens on the form.

    I'm trying to do a threading application; and upto yet this is the only issue as I've had.

    The class in instantiated and is called correctly; likewise in the class function, i'm referencing the form name and accessing the property like that.

    I'm stumped - debugging shows it gets written to, but nothing changes on the form!

    Any help appreciated.

    M
  2. #2
  3. I <3 ASCII
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2003
    Posts
    2,400
    Rep Power
    1233
    Originally Posted by MRb1980
    Hi there Guru's,

    I have a form with a property that writes to a textbox; I call this property from a function within another class, and when the new value is assigned to the textbox (stepping through confirms the data is there) nothing happens on the form.

    I'm trying to do a threading application; and upto yet this is the only issue as I've had.

    The class in instantiated and is called correctly; likewise in the class function, i'm referencing the form name and accessing the property like that.

    I'm stumped - debugging shows it gets written to, but nothing changes on the form!

    Any help appreciated.

    M
    It's been a while since I've done winforms but I believe any changes to UI elements need to be made within the proper thread. If you're in 3.0 or beyond there should be a property on the textbox called 'mustinvoke' if so it's necessary to invoke the command to change the text in a separate thread.

    Hope this is enough to get you pointed in the right direction.

    -MBirchmeier
  4. #3
  5. JavaScript is not spelt java
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2011
    Location
    Landan, England
    Posts
    743
    Rep Power
    165
    You can change the Modifiers property of the textbox from Private to Public, to allow you to write to it. However, this is not the recommended way to do this. Ideally you should, if I understand correctly, subscribe to an event of the form (black-box programming).

    The previous post regarding invoke is a better answer though
    Last edited by AndrewSW; January 2nd, 2013 at 02:18 PM.
    "The mysql extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used." the docs
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    84
    Rep Power
    6
    Thank you both for your replies, however, I'm on this now, and nothing that's suggested works.

    I've tried to invoke to get onto the current thread, which always returns false when I check the textboxes requiredinvoke dohicky.

    I've also tried to change the texboxes modifiers property from friend to public, again, nothing.

    In debug/stepping through shows that the textboxes .text property IS accepting the new value, but just not showing it.

    Still stumped. I'll post pseudo code if needed.

    Cheers,
    M
  8. #5
  9. JavaScript is not spelt java
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2011
    Location
    Landan, England
    Posts
    743
    Rep Power
    165
    Perhaps you need to Refresh the form as well - but this is just a guess, soz.
    "The mysql extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used." the docs
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    84
    Rep Power
    6
    I've sorted this out by using Observers and delegates to pass data between classes to form.

    It's taken me a week, but I've got there; observable objects and update/notify observers as an interface.

    Sweet.

    The way I had originally written this was never going to work; my threads weren't working as I expected them too, and my understanding of their operation wasn't quite grasped - so a week intensive course on how to use them did the trick!

    Thanks for all the help everyone!

    M

IMN logo majestic logo threadwatch logo seochat tools logo