Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating combobox in the other form?

Status
Not open for further replies.

rahmanjan

Programmer
Apr 13, 2003
180
AU
hi all,

I have the main form which has a combobox of all locations. If the location is available it is slected by user if not the user clicks a button next to and another form pops up where user can add,update, delete locations. Obvioiusly when the user adds, delete, updates the locations it should be updated in the main form too.

I do it as follow:

frmCDs frmParent=new frmCDs();
frmParent.FillLocationCombo();

It goes to the sub but doesn't update the combobox i don't know why?

The code in the sub is as:
string sqlstr="select * from tblLocation";
DataSet ds2=new DataSet();
ds2=data.ReturnAll(sqlstr);
cboLocation.DataSource=ds2.Tables[0].DefaultView;
cboLocation.ValueMember="LocationID";
cboLocation.DisplayMember="Location";


regards
 
I think you need to create a static variable that can be referenced from any class. You assign the form to the variable after you create a new instance of the form and before you execute Application.Run

Example:

In the first form make a public static global variable

public static YourFormName GlobalFormVariable = null;

Then in that form do something like this:

Code:
static void Main() 
{
 GlobalFormVariable = new YourFormName();

 Application.Run(GlobalFormVariable);
}
Then you can reference GlobalFormVariable from any class without creating a new instance of this main form.
 
thanks ecannizo,

But still the same problem. Nothing changed.

I don't know why. though i totally requiry my database and wanna refill the combobox.

why it doesn't work.

regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top