I am using an inputbox to allow the user to input some value.
If the user doesnt enter anything and clicks OK Button, i want to display a message box asking for input and show the same input box again.
If the user doesnt enter anything and clicks cancel button, then no messagebox to be displayed. How do i get through this?
RP
Ramesh Praveen
Syncfusion Team
June 25, 2003 11:44 AM UTC
Listen to the OK button's click event, and if a valid value is not in the textbox, fire a message box and then set the focus back to the textbox; otherwise close the dialog by setting it's DialogResult value approriately. Note that the DialogResult property for this button control should be set to None.
-Praveen
RP
Ramesh Praveen
Syncfusion Team
June 25, 2003 11:56 AM UTC
Example:
private void okButton_Click(object sender, System.EventArgs e)
{
if(this.textBox1.Text == String.Empty)
MessageBox.Show("Invalid value entered.");
else
this.DialogResult = DialogResult.OK;
}
RP
Ramesh Praveen
Syncfusion Team
June 25, 2003 12:12 PM UTC
Here is another way of doing it:
private void TextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!this.cancelButton_.Focused)
{
// Do this only when the cancel button is not clicked.
if(invalidState)
e.Cancel = true;
}
}