Google Groups Home
Help | Sign in
Error provider in C#(Win forms)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
mathew  
View profile
(1 user)  More options Jul 18, 1:38 pm
From: mathew <pay...@gmail.com>
Date: Fri, 18 Jul 2008 10:38:12 -0700 (PDT)
Local: Fri, Jul 18 2008 1:38 pm
Subject: Error provider in C#(Win forms)
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
="";

                                        }
                                }

                        }
                }


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn  
View profile
 More options Jul 18, 3:25 pm
From: Glenn <ke4ktza...@gmail.com>
Date: Fri, 18 Jul 2008 15:25:19 -0400
Local: Fri, Jul 18 2008 3:25 pm
Subject: Re: [DotNetDevelopment] Error provider in C#(Win forms)

Are you sure it is getting into the Validating() method?  The code you wrote
is correct, but the program just needs to get into your validation code to
get it reset.  Usually this means that the user must attempt to set focus
away from the control by attempting to go to another field or close the
dialog.

...Glenn

On 7/18/08, mathew <pay...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn  
View profile
 More options Jul 19, 8:27 am
From: Glenn <ke4ktza...@gmail.com>
Date: Sat, 19 Jul 2008 08:27:08 -0400
Local: Sat, Jul 19 2008 8:27 am
Subject: Re: Error provider in C#(Win forms)

Please keep all replies on-list so that others can benefit.

The way the ErrorProvider mechanism works is to validate the controls when
the user sets focus away from them.

For instance, let's say you have a form in which you have the user enter a
name and address.  You would enable validation on the fields that you would
want to perform data validation on to insure that the user entered correct
data (valid address, valid state, etc).  As the user entered the data and
hit tab to go to the next field, that field will be validated.

So, the validation is not going to get called until the user goes to the
next field.  Any error condition from a previous check will remain until the
validation call is done again.

...Glenn

On 7/18/08, mathew <pay...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google