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
Solved

Tabcontrol - Cancel Tab Changed event

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error handling in asp.net site 5 34
Import Data from Multiple Text Files in Excel 12 58
Complex SQL statement in VB.NET 7 31
Groupbox Control ? 2 17
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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