Validate and keep form open

R

Ron Rohrssen

I'm trying to use the ErrorProvider in order to validate
my form. This is working well except that in the event of
a failure on my modal dialog, I'd like to keep the dialog
open.

I open the dialog like this:
if (formOptions.ShowDialog(this) == DialogResult.OK)

When the user clicks on "Save" in the form I do the
validation and regardless of success or failure in the
validation the form is hidden.

How, can I override the button click and keep the form
open?
 
M

Mark D

There is a simple solution. Just set the DialogResult Property in
your button click handler.

private void mButtonSave_Click(object sender, System.EventArgs e)

{
// Perform Validation Test
bool isValid = false;

if(isValid)
{
// Set the Dialog Result of the Form You are Showing when the
validation
// Passes
this.DialogResult = DialogResult.OK;
return;

}
// If the validation fails the Form will stay up.
this.DialogResult = DialogResult.None;
}
 
M

Mark D

Hi Ron,

There is a simple solution. Just set the Dialogresult property from your code.

private void mButtonSave_Click(object sender, System.EventArgs e)
{
// Perform Validation Test
bool isValid = false;

if(isValid)
{
// Set the Dialog Result of the Form You are Showing when the validation
// Passes
this.DialogResult = DialogResult.OK;
return;
}

// If the validation fails the Form will stay up.
this.DialogResult = DialogResult.None;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top