tags:

views:

15

answers:

1

Really wracking my brain here and I'm sure it's something simple I'm missing.

Basically I have a form with two tabs. I'm checking the controls on each tab to see if they're dirty and want to prevent a user from clicking a tab if there are changes on the current tab.

I had thought if I check the dirty variable and just set the tab index to the one that hasn't been selected I'd be fine but every time I programatically set a tab's property, it fires off a bunch of the tab's events that just produce an undesireable result such as the right control set is showing but the wrong tab is selected.

Here is the code for as close as I've gotten to getting it to work.

Private Sub objTabs_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles objTabs.Selected
    If bIsDirty Then
        If Me.objTabs.SelectedIndex = 1 Then
            Me.objTabs.SelectedTab = tabLetterofCreditBanks
            Me.objTabs.SelectTab(0)
        Else
            Me.objTabs.SelectedTab = tabWireTransferBanks
            Me.objTabs.SelectTab(1)
        End If
    End If
End Sub

Thanks in advance.

+2  A: 

Try using the Selecting event instead of the Selected event - this will give you the opportunity to override the user's behavior (i.e. setting TabControlCancelEventArgs.Cancel to True).

Andrew Hare
Nice, I knew it had to be something simple I was missing. Thanks.
Tom