?
Solved

Invoking the Validation event when an Accept Button on the windows form is clicked

Posted on 2005-02-24
4
Medium Priority
?
499 Views
Last Modified: 2012-06-27
Hi,

I have a bunch of controls on the user form and a error provider.  What I am trying to do is to invoke the validation events when the Accept button is selected.  Any ideas?

-Nauman.
0
Comment
Question by:nauman_ahmed
  • 2
4 Comments
 
LVL 9

Assisted Solution

by:Wim_Bl
Wim_Bl earned 1000 total points
ID: 13395631
something like this ?

btnAccept_OnClick(.....)
dim myControl as new Control

for each myControl in me.Controls
     myControl.Validate()
next

Not sure about the exact syntax but you get the idea.

greetings
0
 
LVL 16

Accepted Solution

by:
OliWarner earned 1000 total points
ID: 13399974
I'm assuming you're in VS.net

click on the accept button. In the properties window, click the lightning bolt at the top, and go down to the click event. Either specify a current authentication function or double click and it will make you a new one.
0
 
LVL 25

Author Comment

by:nauman_ahmed
ID: 13404146
Thanks a lot  for the help experts :)

I have form that has Tab Control and I want to validate the controls contained in the tab pages.  I have written the following function that I am invoking when the Accept button is clicked:

private void ValidatePages(int ParentTabControlIndex, TabControl tc)
            {
                  for(int i = 0;i<tc.TabPages.Count;i++)
                  {
                        TabPage page = tc.TabPages[i];
                        bool isValid = true;
                        foreach(Control c in page.Controls)
                        {
                              if (c.GetType() == typeof(TextBox))
                              {
                                    if (c.CausesValidation == true)
                                    {
                                          Console.WriteLine(c.Text);
                                          if (c.Text == "")
                                          {      
                                                isTabPageValid = false;
                                                isValid = false;
                                                if (c.Tag != null)
                                                {
                                                      this.errorProvider.SetError(c,c.Tag.ToString());
                                                      c.Focus();
                                                }
                                          }
                                    }
                              }
                        }      
                        if (isValid == false)
                        {
                              this.tcServiceManager.SelectedIndex = ParentTabControlIndex;
                              tc.SelectedIndex = i;
                              break;
                        }
                  }


And on the Accept Button click even I am calling it as follows:

if (this.isTabPageValid == true)
                        {
                              this.ValidatePages(1,this.tcDatabase);
                        }
                        if (this.isTabPageValid == true)
                        {
                              this.ValidatePages(2,this.tcSMTP);
                        }

Its working fine almost, however, after the first validation has been done the Accept button stop validating the  after I called the ValidatePages function first time.  Any suggestions?

Thanks, Nauman.
0
 
LVL 25

Author Comment

by:nauman_ahmed
ID: 13404282
I got the error :) isTabPageValid is a gloabally defined value and I had to change it to true if page is valid:

if (c.Text == "")
                                          {      
                                                isTabPageValid = false;
                                                isValid = false;
                                                if (c.Tag != null)
                                                {
                                                      this.errorProvider.SetError(c,c.Tag.ToString());
                                                      c.Focus();
                                                }
                                          }
                                          else
                                          {
                                                this.isTabPageValid = true;
                                          }

Is there any other better approach that this?

-Thanks,  Nauman
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question