I have this situation: in my form Order
there's a combobox with many products inside. it is expected that the user could add products to the combobox to use in Order
, but this is made via another form called ProductAdd
, basically made with a textbox where the user types the name of the product and it's added with a button. Since I can't have access to the combobox in the Order
form when I'm in the ProductAdd
form, I made a method in Order
which add into the combobox the product passed.
The string is not added to the combobox in the other form.
This is the method in Order to operate in its combobox
public void addProductInCbb(string newProduct)
{
cbbProdotti.Items.Add(newProduct);
}
This is the method in the other form ProductAdd
to add the string in my cbb
private void btnConfirmNewProduct_Click(object sender, EventArgs e)
{
Order o = new Order(new Form1()); //that's because I think I need an instance of Order to call the method... is that correct?
String newProduct= txtNewProduct.Text; //get product string from txt
//boring checks to say if product already exists
bool found = false;
ArrayList products= o.getProducts();
foreach(String product in products)
{
if (product.Equals(newProduct)) found = true;
}
if (!found)
{
o.addProductInCbb(newProduct); //method call from Order
MessageBox.Show("Success!","", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else MessageBox.Show("Product already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
-EDIT- I made the weird "Order o = new Order(new Form1())" constructor because: to call addProductInCbb(string) I ned an Order instance, BUT in turn, the Order constructor ned a Form1 parameter, because when the Order is completed, a PDF is created with all the data from both form1 and Order form... May this cause my issue?