HI guys,
I am developing a winform and need to update the contents of a combo box at runtime. I currently click a button that brings up a new dialog and click save. I then return to the parent form and at that point i rebind the combo box to the collection that retrieves my new saved item from the DB. Problem is that i can see the item when I debug and step through but the combo box has not been refreshed to show the new item.
I am developing a winform and need to update the contents of a combo box at runtime. I currently click a button that brings up a new dialog and click save. I then return to the parent form and at that point i rebind the combo box to the collection that retrieves my new saved item from the DB. Problem is that i can see the item when I debug and step through but the combo box has not been refreshed to show the new item.
Code:
public void BindSuppliers()
{
string strConnection = string.Empty;
try
{
SupplierCollection oCollection = Data.GetSuppliers(strConnection);
ddlSuppliers.Items.Clear();
ddlSuppliers.DataSource = oCollection;
ddlSuppliers.DisplayMember = "SupplierName";
ddlSuppliers.ValueMember = "SupplierId";
}
catch
{
// log
}
}
private void btnSave_Click(object sender, EventArgs e)
{
Supplier s = new Supplier();
try
{
s.SupplierName = txtSupplier.Text;
Data.AddSupplier(s);
CloseForm();
}
catch (Exception oEx)
{
// log
}
}
private void CloseForm()
{
Form1 f = new Form1();
try
{
f.BringToFront();
f.BindSuppliers();
this.Close();
}
catch (Exception oEx)
{
// log
}
}