Hi all
I use an error provider in my win form in order to validate some text
boxes value.
My problem is this:if the user input something wrong then the error
provider shows him a
notification,It is logical,but when user correct the value the error
notification is still visible to him
and the user think that he made a mistake again.The same problem is
happened in DatagridView.
what should I do to prevent this?(the error provider disappeared when
user correct his value when he entered)
the following code is a piece of my code which I use:
private void txtName_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (!IsNameValid())
{
e.Cancel = true;
}
}
private bool IsNameValid()
{
txtName.Text = txtName.Text.Trim();
if (txtName.Text == string.Empty)
{
erp1.SetError(txtName, "Name must not be blank.");
return false;
}
else
{
erp1.SetError(txtName, "");
return true;
}
}
---------------------DataGridView-----------------
void DataGridView1CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].HeaderText=="Input")
{
char[] chArray=e.FormattedValue.ToString().ToCharArray();
bool flag=false;
foreach(char ch in chArray){
if(!Char.IsDigit(ch)){
flag=true;
e.Cancel=true;
break;
}
if(flag==true){
dataGridView1.Rows[e.RowIndex].ErrorText = "Invalid Product
Image";
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText =
"The file name must end with '.gif'.";
}
else
{
dataGridView1.Rows[e.RowIndex].ErrorText = "";
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText
="";
}
}
}
}