hello. i have problem with c# multiple form app. in my first form i
have a combo box, a list, a text box and an add item button. in the
combo box i have a list of products. once i choose a product from combo
box and enter the quantity in the text box, it will show up on my list.
but if i click on an empty string from combo box such as "" and click
on add item, it will take me to a subform where i can put in the
specifications of the product. in the second form i have the product
name and other specifications. i also have an update button when the
name of the product in the second form's text box is entered and update
button is clicked, it should upload the name of the product to the
first form's combo box.
usually when u want to pass data u have the driver class, there u
create an object of the first form and once in the first form, u create
an object of the second form and pass the first form's values into the
second form. but in this case its different. you are creating an object
of the first form in the driver class. then once the user is in the
first form and clicks add item for a blank string in the combo box, an
object of the second form is created. once product name is entered into
the second form and the update button is clicked the data has to be
passed back to the first form. so it is back and forth.
here is my code
my code is attached
THANK YOU A LOT IN ADVANCE!
Loading
Raaj KumarPosted Feb 17, 2010, 7:29 AM
Thanks
Raaj
Thomas AndersonPosted Feb 17, 2010, 4:43 AM
Raaj KumarPosted Feb 16, 2010, 5:45 AM
In ProductForm create an event like OnClosed,
public event EventHandler OnClosed;
After completing the operation ie., in UpdateButton_Click and CancelButton_Click add the folllowing code,
if (OnClosed != null) { OnClosed(this, null); }
In ShippingListForm register the OnClosed event like this,
pF.OnClosed += new EventHandler(pF_OnClosed);
void pF_OnClosed(object sender, EventArgs e)
{
//add you code here
}
So whenever you close or update in ProductForm this event will be triggered such that you would be having the control back. If you want data from the ProductForm expose a property as public so that you can have the value in ShippingListForm. I have attached your code with minor modification. Please find the attachment.
Hope this helps you.
Please let me know you face any problem