vlad
vlad

Reputation: 159

Winforms How to pass data from Form back to user control?

How do i pass data from a form i opened in userControl back to the userControl? userControl code:

 public AdminControl()
    {
        InitializeComponent();
        SetGridColomns();
    }
 private void btnEditInfo_Click(object sender, EventArgs e)
    {
        Form editForm = new EditForm();

        if (editForm.ShowDialog() == DialogResult.OK)
        {
        // trying to get Owner2 here but failing
        }
    }

Form Code:

 public partial class EditForm : Form
{

    public CompanyOwner Owner2;
    public EditForm()
    {
        InitializeComponent();
        Owner2 = new CompanyOwner();

    }
    private void btnSave_Click(object sender, EventArgs e)
    {
        Owner2.Address = tbAddress.Text;
        Owner2.CompanyName = tbCompanyName.Text;
        Owner2.Email = tbEmail.Text;
        Owner2.Phone = tbPhone.Text;
    }
}

When i try to get editForm.Owner2 nothing shows up. I tried making it static, using strings instead of class and still nothing. Where im going wrong?

Upvotes: 0

Views: 63

Answers (1)

vlad
vlad

Reputation: 159

Nvm i find the mistake ... i should use EditForm instead of Form:

EditForm editForm = new EditForm();

Upvotes: 2

Related Questions