Solved

Tabcontrol - Cancel Tab Changed event

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

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

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…
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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