Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
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
 
Old January 12th, 2010, 02:57 AM
Registered User
 
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old January 12th, 2010, 03:55 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old January 12th, 2010, 08:22 PM
Registered User
 
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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,
 
Old January 13th, 2010, 05:47 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Simply call the method:

Code:
cboItem_load()
You are aware that the ShowDialog() method waits until the form closes aren't you?
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old January 13th, 2010, 08:22 PM
Registered User
 
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old January 14th, 2010, 03:37 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

err, I did.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Close Form1 headworth Visual Basic 2008 Essentials 1 September 10th, 2009 03:18 AM
Show Form2, only then run Routine1 peterasimpson VB How-To 5 April 29th, 2008 06:47 AM
document.form1 MuthuAL Classic ASP Databases 5 January 4th, 2005 10:00 AM
can not find form1 specified error sadiku ASP.NET 2.0 Basics 1 October 8th, 2004 05:28 PM
Refresh a combobox without postback Eddy ASP.NET 1.x and 2.0 Application Design 1 March 10th, 2004 12:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.