views:

312

answers:

3

I have a custom form that's returning the values to the main form but it's not seeing the variables. I don't think I'm making this very clear so I'll include the links to the examples of what I'm trying to do.

http://stackoverflow.com/questions/818785/return-values-from-dialog-box
too long to display

I know I'm probably overlooking something very easy and or obvious but here is what I have.

form1.cs
private void addTime_Click(object sender, EventArgs e)
{
    Form add = new addTime(false, new string[] { "", "" });
    if (add.ShowDialog(this) == DialogResult.OK)
    {
        // the line not working
        Label1.Text = add.Details;
        // reports with:'System.Windows.Forms.Form' does not contain a
        // definition for 'Details' and no extension method 'Details' accepting       
        // a first argument of type 'System.Windows.Forms.Form' could be found (are you
        // missing a using directive or an assembly reference?)
    }
}

addTime.cs
internal class addTime : Form
{
    //..
    private string _details;
    public string Details
    {
        get { return _details; }
        private set { _details = value; }
    }

    private string _goalTime;
    public string GoalTime
    {
        get { return _goalTime; }
        private set { _goalTime = value; }
    }

    private void applybtn_Click(object sender, EventArgs e)
    {
        Details = detailslbl.Text;
        GoalTime = goalTimelbl.Text;
    }
}

Thanks in advance.

+3  A: 

You need to set the DialogResult property of the child form

DialogResult = DialogResult.OK

in the button click .

sirrocco
+3  A: 

Your 'add' variable is of type Form, not addTime and the Form type does not have a Details property.

Try this line instead:

addTime add = new addTime(false, new string[] { "", "" });
Chris Dunaway
WOW! I knew it had to be something simple! Lol, thanks though I feel like an idiot now.
Nyight
Nice catch, I missed that
Ed Swangren
A: 

you need to set the form's dialogResult property to OK. You haven't specified it in your code.

After the correct criteria have been met you would set it like this.

If (//condition)
{
this.DialogResult = DialogResult.OK;
This.Close();
}
gsirianni