Refresh comboxbox in form1 after form2 is closed
-
Dear developers, I am coding a very small project for my study. I want to refresh form1 after form2 is closed. For example, I open form1 and click one button to open form2 and in form2 I can insert data to the database (ex : tblItem). In addition, combobox in form1 retrieves data from the database (tblItem) too. So, after inserting data from form2 and when I close the form2, I want the comboxbox in form1 refresh to retrieve the last update of tblItem data. Here is my code to open form2 form2 frmitem = new form2(); frmitem.ShowDialog(); Please advise, thanks. Visoth
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
-
Dear developers, I am coding a very small project for my study. I want to refresh form1 after form2 is closed. For example, I open form1 and click one button to open form2 and in form2 I can insert data to the database (ex : tblItem). In addition, combobox in form1 retrieves data from the database (tblItem) too. So, after inserting data from form2 and when I close the form2, I want the comboxbox in form1 refresh to retrieve the last update of tblItem data. Here is my code to open form2 form2 frmitem = new form2(); frmitem.ShowDialog(); Please advise, thanks. Visoth
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
You can paste your code directly behind the ShowDialog() row. If you call the ShowDialog() function, the main form will "sleep" until the dialog window is closed. For example, if you call ShowDialog(), and on the next line you call Messagebox.Show(), the messagebox will be shown as soon as the dialog window is closed. So your code might look like this:
form2 frmitem = new form2();
frmitem.ShowDialog();UpdateMyComboBox(); // this function will be called as soon as the dialog window is closed
-
You can paste your code directly behind the ShowDialog() row. If you call the ShowDialog() function, the main form will "sleep" until the dialog window is closed. For example, if you call ShowDialog(), and on the next line you call Messagebox.Show(), the messagebox will be shown as soon as the dialog window is closed. So your code might look like this:
form2 frmitem = new form2();
frmitem.ShowDialog();UpdateMyComboBox(); // this function will be called as soon as the dialog window is closed
-
Sorry, can give explain me more detail than this? :)
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
It's not possible to explain it in more detail, because it's just too simple... Maybe my explanation was not clear enough, I'll try once more. You asked how to refresh a combobox after a child form has closed. The answer is simple - the code that refreshes the combobox should be right behind the form.ShowDialog() line. It will be executed as soon as the child form is closed, and that's what you want.
-
It's not possible to explain it in more detail, because it's just too simple... Maybe my explanation was not clear enough, I'll try once more. You asked how to refresh a combobox after a child form has closed. The answer is simple - the code that refreshes the combobox should be right behind the form.ShowDialog() line. It will be executed as soon as the child form is closed, and that's what you want.
private void lkl_additem_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) //form1 { //Open form2 from form1 form2 frmitem = new form2(); frmitem.ShowDialog(); this.cbo_itemname.Refresh(); // This is a combobox in form1 which I wanna update when form2 closes. } Is the code like this??? However, it doesn't work. :(
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
-
private void lkl_additem_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) //form1 { //Open form2 from form1 form2 frmitem = new form2(); frmitem.ShowDialog(); this.cbo_itemname.Refresh(); // This is a combobox in form1 which I wanna update when form2 closes. } Is the code like this??? However, it doesn't work. :(
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
-
You can paste your code directly behind the ShowDialog() row. If you call the ShowDialog() function, the main form will "sleep" until the dialog window is closed. For example, if you call ShowDialog(), and on the next line you call Messagebox.Show(), the messagebox will be shown as soon as the dialog window is closed. So your code might look like this:
form2 frmitem = new form2();
frmitem.ShowDialog();UpdateMyComboBox(); // this function will be called as soon as the dialog window is closed
Thnx a ton. Ur solution is the best :-D