Checking whether value is entered into a control and preventing focus to go out if no value is entered.
Windows Forms Input Validation with Validating Event and ErrorProvier Control
private void txtName_Validating(object sender, CancelEventArgs e)
{
if (txtName.Text == "")
{
errorProvider1.SetError(txtName, "Name cannot be blank");
e.Cancel = true;
}
else
errorProvider1.SetError(txtName, "");
}
bruceraymond 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.