c# - setting combo box value through property winform -


i have combobox need set class, trying set value within public property. have far, combo box not populating.

public string title {     set      {          _title = value;         cmb_title.text = value;     }          {          return _title;      } } 

i have tried cmb_title.selectedtext = value, index , can think i'm not sure if because setting in property. ideas appreciated.

please note pass form1 owner form2 can access property title. also, example. if collection should same across forms, in real life bind collection in dal or business layer can shared, not add items this.

public partial class form1 : form {     private string _title = "";      public form1()     {         initializecomponent();     }      private void form1_load(object sender, eventargs e)     {         cmb_title.items.add("cat");         cmb_title.items.add("dog");         cmb_title.items.add("bear");     }      public string title     {         set         {             _title = value;             cmb_title.selectedindex = cmb_title.findstringexact(value);         }                 {             return _title;         }     }      private void button1_click(object sender, eventargs e)     {         var form2 = new form2();         form2.show(this);     } }    public partial class form2 : form {     public form2()     {         initializecomponent();     }      private void form2_load(object sender, eventargs e)     {         cmb_title2.items.add("cat");         cmb_title2.items.add("dog");         cmb_title2.items.add("bear");      }      private void cmb_title_selectedindexchanged(object sender, eventargs e)     {         var f1 = this.owner form1;         f1.title = cmb_title2.text;     } } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -