Urbycoz Urbycoz - 1 year ago 104
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download