I have UI form in C# with a bunch of combo boxes and a text box. I have the validated and validating events associated with the text box to make sure the user selects valid input. I also have a "View Results" and "Export Results" buttons in the form. When I click on any of the two buttons, it surely validates the text box input but doesn't do the action that the button is supposed to do. I am having to click the button again to trigger the action that the button is supposed to do.
What should I do so that the button click event does both validation and also action it is intended to do?
Here is excerpt from my code
private void NameTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!isValidName())
{
e.Cancel = true;
NameTextBox.Select(0,NameTextBox.Length);
InvalidPMLabel.Visible = true;
InvalidPMLabel.Text = "Invalid Name";
ExportButton.Enabled = false;
ViewResultsButton.Enabled = false;
GroupTextBox.Clear();
}
}
private void NameTextBox_Validated(object sender, EventArgs e)
{
string combination = null;
int index = -1;
sql = "select .......";
dSet = get_data(sql);
MaxRows = dSet.Tables[0].Rows.Count;
if (MaxRows != 0)
{
dSet.Clear();
...
...
}
else
{
...
...
...
}
GroupTextBox.Text = dSet.Tables[0].Rows[index]["group"].ToString();
}
private void ViewResultsButton_Click(object sender, EventArgs e)
{
view_marks();
view_grade();
}