Solved

Tabcontrol - Cancel Tab Changed event

Posted on 2004-09-07
4
1,516 Views
Last Modified: 2007-12-19
Hi,

Having real problems with this issue. Thanks for clicking

Have a TabControl. When on the first tab, want to check that a ComboBox has a value in before allowing the user to change the TabPage.

Best way to do this would be to cancel the event if ComboBox="" otherwise prgress as normal.

Problem is I'm using the Private Sub _Tabcontrol_TabPage0_Validating event, so that can e.Cancel =True if the ComboBox =""

Problem is this validating event is not firing when the tab is changed.

Have seen a couple of posts on google search saying the same thing.

Can anyone possibly enlighten me to a fix or "get around"???

Rob
0
Comment
Question by:RobKearney
  • 2
4 Comments
 
LVL 8

Assisted Solution

by:gregasm
gregasm earned 50 total points
ID: 11998106
0
 
LVL 4

Accepted Solution

by:
Javert93 earned 150 total points
ID: 12010825
"Validating" events are only good for user input controls, and only fire when then focus is move to a control that has it's CausesValidation property set to True. So in your case, this event won't ever fire, and even if it did, it would only fire when the selection changed from a tab (the control itself) to another control. The event you want is the TabIndexChanged event. Unfortunately, this only fires after the user has selected a tab, not before. However, this code will probably do what you want:

    Private CurrentTabPage As TabPage

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CurrentTabPage = TabControl1.SelectedTab
    End Sub

    Private Sub TabControl1_TabIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.TabIndexChanged
        Dim bIsValid As Boolean

        ' Validate the tab here and set the result to bIsValid

        If Not bIsValid Then
            ' The data is invalid, revert the selection
            TabControl1.SelectedTab = CurrentTabPage
        End If
        CurrentTabPage = TabControl1.SelectedTab
    End Sub
0
 
LVL 4

Expert Comment

by:Javert93
ID: 12010974
1) Here is an MSDN magazine article that discusses how to create an MSCOMM control alternative in .NET: http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx

2) According the MSDN documentation, "A process uses the CreateFile function to open a handle to a communications resource. For example, specifying COM1 opens a handle to a serial port, and LPT1 opens a handle to a parallel port. If the specified resource is currently being used by another process, CreateFile fails. Any thread of the process can use the handle returned by CreateFile to identify the resource in any of the functions that access the resource." This seems to clearly indicate that serial ports are not sharable outside of a single process. There is a good chance that greg's example is either replacing the default driver, use WaitComm() to intercept serial events.
0
 

Author Comment

by:RobKearney
ID: 12014919
Hi Javert93, gregasm.

Thanks to both of you for your posts

gregasm - thanks for pointing me in the direction of those two PAQ's. made me realise needed to attack from anohter angle

And that solution was to do what Javert93 mention. Basically upon SelectedIndexChanged event, check to see that the comboBox <> "", and if it did revert it back to original tab and give out a message.

You have to be careful though, because the event fires twice due to changing the tab twice. I removed and addedhandler back in to overcome this.

Javert93's answer is basically the solution I came up with as well. Which adds credability to both our answers.

Thank you both for taking the time to reply to the post.

Rob
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting C# Objects into JSON file 7 65
System32Int Error 8 56
Create a form which is copy of a form in vb.net 2 34
Populating an array of locale_time_info 8 37
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now