Urbycoz Urbycoz - 8 months ago 49
Vb.net Question

Set selected tab without selectedIndexChanged event firing

Is there a way to set the selected tab of a tabControl without the selectedIndexchanged event firing?

e.g. Here the event fires when selecting myTabPage2 because myTabPage1 is the default:

Private Sub setupTabControl
If blnHasAccount=true then
End if
End sub

Private Sub MyTabControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyTabControl.SelectedIndexChanged
'Do stuff (but only when user has actually changed the tab themselves)
End Sub


When you set the new tabpage you could remove the event handler

    RemoveHandler MyTabControl.SelectedIndexChanged, AddressOf Me.MyTabControl_SelectedIndexChanged
    .. do your works to change page here
    .. and then reconnect
    AddHandler MyTabControl.SelectedIndexChanged, AddressOf Me.MyTabControl_SelectedIndexChanged
End Try

It's important to enclose everything in a Try Finally to recover correctly from exceptions