I have Form1 which contains a combobox which show some number saved in Database and it also contain a button(butn2
) which on click popups a another form and another button(butn1
) which updates the combo from database.
Here on this form (Form2, Child form of some sort)i try to updat the data of the combobox of previous form(parent one) on button click by creating object of Form1
But when i open and see the combobox it still show the same data(it is not updated).
Is it possible to update the UI from combobox from one form to another ? My code is
Form1 code:
public Form1()
{
InitializeComponent();
}
Form1.Designer.cs:
Button butn1;
Button butn2;
ComboBox cmb1;
private void InitializeComponent()
{
cmb1 = new ComboBox();
butn1 = new Button();
}
this.butn1.Click += new System.EventHandler(this.button_Save_Click);
this.butn2.Click += new System.EventHandler(this.button_Save_Click2);
public void button_Save_Click(object sender, System.EventArgs e)
{
UpdateComboBoxFromMySQL.InsertdataInCombo(this.cmb1 ); //Here i add data in combox through database, the code is correct i verfied it
}
public void button_Save_Click2(object sender, System.EventArgs e)
{
Form2 frm2 = new Form2();
frm2.show();
}
Form2 code:
Button butn2 = new Button();
//first i add some data to database, which are added i have seen the table-columns by opening DB. Now i want to update the Combobox from that data
Form1 obj1 = new Form();
this.butn2.Click += new System.EventHandler(obj1 .button_Save_Click); //It calls the function button_Save_Click, i saw on debugging but still it do not update the data.
How to update this combobox of Form1 from Form2 button click?