Solved

Tabcontrol - Cancel Tab Changed event

Posted on 2004-09-07
4
1,510 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

12 Experts available now in Live!

Get 1:1 Help Now