c# - Displaying selected listbox item in textbox on seperate form? -


i attempting take a selected item in listbox , have displayed in textbox in different form. hoping when click button on mainform triggers selected item displayed in textbox

in mainform have:

public static string mylistboxstring;  private void lstdictionary_selectedindexchanged(object sender, eventargs  e) {      mylistboxstring = lstdictionary.selecteditem.tostring(); }  private void btnedit_click(object sender, eventargs e) {    editwordform myeditwordform = new editwordform();    myeditwordform.selectedvalue = mylistboxstring;    myeditwordform.showdialog();     this.dictionarytableadapter.fill(this.dictionarydataset.dictionary);  } 

in second form attempting place selected word have:

public partial class editwordform : form {     public editwordform()     {         initializecomponent();          wordtextbox.text = mainform.mylistboxstring;                 }      public string selectedvalue     {         set         {            wordtextbox.text = value;         }     }   } 

edit*

private void button1_click(object sender, eventargs e) {  using (sqlconnection connection =  new sqlconnection(connectionstring)  {      connection.open();      sqlcommand cmd = new sqlcommand("update dictionary set word=@word", connection);              cmd.parameters.addwithvalue("@word", wordtextbox.text);             cmd.executenonquery();             this.close();         }     } 

now able edit word save database. when saves replaces 10 words new 1 opposed 1 specific entry. have read , looked seems code should work far displays empty field in text box after running application. thing can think of using dataset populate initial listbox , throwing off? guidance appreciated!

in editwordform add property called selectedvalue

public string selectedvalue {      set      {           wordtextbox.text = value;      } } 

from main form set property before showing form.

private void btnedit_click(object sender, eventargs e) {    editwordform myeditwordform = new editwordform();    myeditform.selectedvalue = lstdictionary.getitemtext(lstdictionary.selecteditem);     myeditwordform.showdialog();     this.dictionarytableadapter.fill(this.dictionarydataset.dictionary);  } 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -