 |
| C# 2005 For discussion of Visual C# 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 12th, 2010, 02:57 AM
|
|
Registered User
|
|
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Refresh combobox 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 insert data to the database (ex : tblItem). In addition, combobox in form1 retrieves data from the database (tblItem) too when formload (form1 load). 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
|
|

January 12th, 2010, 03:55 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
I don't see the problem. Just put the code to update the combo box after the ShowDialog() line.
Ideally this would be the same code that loaded the combo box in the first place, so extract that code into a method and call it in both places.
|
|

January 12th, 2010, 08:22 PM
|
|
Registered User
|
|
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Refresh combobox in form1 after form2 is closed
Here is the code that I load it to combobox on form1
public void cboItem_load()
{
try
{
clsConnection.dbcnn.Open();
string str = @"Select iid, name_en From tbl_item";
OleDbDataAdapter dtadaptor = new OleDbDataAdapter(str, clsConnection.dbcnn);
DataSet dtset = new DataSet();
dtadaptor.Fill(dtset, "tbl_item");
this.cbo_itemname.DataSource = dtset;
this.cbo_itemname.DisplayMember = "tbl_item.name_en";
this.cbo_itemname.ValueMember = "tbl_item.iID";
this.cbo_itemname.SelectedIndex = -1;
clsConnection.dbcnn.Close();
}
catch (Exception Er)
{
MessageBox.Show(Er.Message, "Exception");
}
}
When I close form2 what should I do to make the combobox on form1 refresh?
***** I am a beginner in C Sharp, so I hope to learn from you all.
Thanks,
|
|

January 13th, 2010, 05:47 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Simply call the method:
You are aware that the ShowDialog() method waits until the form closes aren't you?
|
|

January 13th, 2010, 08:22 PM
|
|
Registered User
|
|
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Refresh combobox in form1 after form2 is closed
Sorry bro, I even do not know how to call a sub procedure. Would you mind to write me down a code?
Many thanks,
Visoth
|
|

January 14th, 2010, 03:37 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
err, I did.
|
|
 |