Search code examples
c#winformsshowdialogdialogresult

Trouble with Form.DialogResult


private void mnuCustomerAdd_Click(object sender, EventArgs e)
    {
        CustomerForm frmCust = new CustomerForm("Add A New Customer");

        int index = lstCustomers.SelectedIndex;
        if (index != -1)
            frmCust.CustomerData = new Customer(customerMngr.GetCustomer(index).ContactData);


        MessageBox.Show("dev1");
        DialogResult dr = frmCust.ShowDialog();
        if (dr == DialogResult.OK)
        {
            MessageBox.Show("dev2");
            if (frmCust.ReadInput())
            {
                MessageBox.Show("dev3");
                customerMngr.AddCustomer(frmCust.CustomerData);
            }
            else
                MessageBox.Show("Please supply all necessary fields with the correct information");
        }
        UpdateCustomerList();

    }

Don't understand what I'm doing wrong here, I want to execute the conditional statements if the user hits OK in the Form that appears at frmCust.ShowDialog(). At the moment I can only get to "dev1".


Solution

  • Perhaps your dialog isn't setting the dialog result. Make sure your OK and Cancel buttons have their DialogResult properties set to what you expect.