?
Solved

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

Posted on 2005-02-24
4
Medium Priority
?
493 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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