Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2004

Tip: Looking for answers? Try searching our database.

Validating Event handler doesn't allow Cancel of Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Royce Fickling - 13 May 2004 17:53 GMT
Hi,

I have implemented a form using a TabControl with 5
TabPages. On one page, I have a number of controls, i.e.,
ComboBoxes, RadioButtons, NumericUpDowns, etc. I want to
validate the data entered by the user into these controls
and at the same time allow the user to cancel the form if
he wishes. To implement this, I copied some sample code:

private void tabControl1_SelectedIndexChanged(object
sender, System.EventArgs e)
{
    tabControl1.TabPages
[tabControl1.SelectedIndex].Focus();
    tabControl1.TabPages
[tabControl1.SelectedIndex].CausesValidation = true;
}

private void tpSchedule_Validating(object sender,
CancelEventArgs e)
{
    bool bValid = true;
    if ((string)cboSchedule.SelectedItem == "Weekly")
    {
        if (cboRunOnDOW.SelectedItem.ToString()
== "")
            bValid = false;
    }
}

My problem is that the TabPage always has the focus and
won't allow the Cancel button push to be handled. If I
remove the first line of the SelectedIndexChanged() event
handler, the Cancel button push is handled, but then the
validation stuff is never invoked. Does anyone know how to
fix this?

Thanks,
Royce
Dmitriy Lapshin [C# / .NET MVP] - 14 May 2004 09:09 GMT
Hi,

Safety first - have you ensured the Cancel button has its CausesValidation
property set to False?

> Hi,
>
[quoted text clipped - 35 lines]
> Thanks,
> Royce

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.