c# - Why Windows Form TextBox won't update from outside class? -


newbie here. i'm running visual studio c# express 2008. have 2 windows forms, each textbox. textboxes update within same class not result of invoked method outside class. need able update tbrooms.text when updatelistofrooms() method invoked. i've outlined problem in pseudo-code below. appreciate help!

flocations.cs

flocations_load() {     this.tblocations.text = properties.settings.default.locationid + " locationsload";  --updates }  dgvlocations_selectionchanged() {     var rooms = new frooms();     rooms.tbrooms.text = properties.settings.default.locationid + " locationssselectionchanged";  --updates     rooms.updatelistofrooms();   } 

frooms.cs

frooms_load() {     this.tbrooms.text = properties.settings.default.locationid + " roomsload"; --updates  }  updatelistofrooms() {     this.tbrooms.text = properties.settings.default.locationid + " roomsupdatelistofrooms";  --does not update; still says "roomsload" } 

updated 8/20/14: i've been busy bee :) read parts of tutorial @jmcilhinney , decided approach including references 2 forms, locations , rooms, in mainmenu class launches them:

(mainmenu.cs) instances of locations , rooms created. in constructor, 'rooms' passed 'locations' instance , both forms shown.

(locations.cs) rooms instance created @ class scope can seen methods of class. in constructor, instance set 1 being passed mainmenu means class working same instance created in mainmenu. when user changes selection on dgvlocations, 'dgvlocations_selectionchanged' event fired invokes rooms.updaterooms method.

(rooms.cs) 'updaterooms' method displays new set of rooms based on passed value of 'locationid'.

this link helpful. visual c# - access instance of object created in 1 class in another.

public partial class mainmenu : form {        locations locations;     rooms rooms;          public mainmenu()     {                rooms = new rooms();                 locations = new locations(rooms);                locations.show();         rooms.show();         initializecomponent();     } }  public partial class locations : form {        rooms rooms;      public locations(rooms r)     {         rooms = r;         initializecomponent();     }      private void locations_load(object sender, eventargs e)     {         // populate this.dgvlocations using sql query.     }      private void dgvlocations_selectionchanged(object sender, eventargs e)     {          // update rooms instance current locationid.         rooms.updaterooms(dgvlocations.currentcell.value.tostring());     }  }  public partial class rooms : form {         public rooms()         {                initializecomponent();         }          private void rooms_load(object sender, eventargs e)         {                // populate this.dgvrooms using sql query.         }          public void updaterooms(string locationid)         {             // update dgvrooms based on user changing locationid in dgvlocations         } } 

in first code snippet, create new frooms object never call show or showdialog method, means never display user. means changes make form not seen. presumably user can see frooms object though, not making changes one.

consider this. let's give note pad , open , @ first page. let's buy new note pad , write on first page of it. expect see words wrote magically appear on page in front of you? of course not. both holding note pad 2 different note pads. you're looking @ 1 , i'm writing on other, won;t see write.

the same goes forms. both frooms objects 2 different frooms objects. changes make 1 not affect other. if want user see changes make must make changes frooms object user looking at.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -