Question

I attempted to try perform this code based on the How do I pass a value from a child back to the parent form?

However, I just wanted to get the Date Value to pass on to the MDI Mainform with a function that it will load all data in the datagridview (in the main form) Child Form which is ShowDialogue Child Form which is ShowDialogue

Main MDI Form Parent which after the Child Form Dialogue is closed and the data on the datagridview will be refresh Main MDI Form Parent which after the Child Form Dialogue is closed with a value which is "Date" and the data on the datagridview will be refresh upon getting the Date Value Child to the function which to display data.

Sorry for the confusion because I end up asking here.

Was it helpful?

Solution

You don't have to have the child form updating fields on the parent form.

Instead, on the child form, create a property that will return the value from the DateTimePicker.

public DateTime PurchaseOrderDate
{
    get { return dateTimePicker1.Value; }  // your PO date picker control
}

Then on the main form, retrieve the value when the child form is closed:

using (mPOrder newPO = new mPOrder())
{
    newPO.ShowDialog();

    var poDate = newPO.PurchaseOrderDate;

    // do something with the date - update grid or whatever
}

OTHER TIPS

Here is some trick you can use to get date value to parent form

you need to create method in your child form is public.

public DateTime GetDateFromChild(){
  this.ShowDialog();
return Convert.ToDateTime(this.txtdatevalue.text);

}

In your Parent Form

childform form = new childform();
Datetime getdate = form.GetDateFromChild();

This is not tested but I have used this type of method to pass the value to one to another

antoher option is

create a Static class and assign its property value to your date and get back date value from parent form to it..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top