fedeteka fedeteka - 1 month ago 18
Vb.net Question

Select Case to handle active TabPage

A program with a Form and a TabControl. I need to handle what happens when the user close the form according to the active TabControlPage

Is working with If - Then like this

If PanelChooserTabControl.SelectedTab Is SelectionTabPage Then
'What I want
End If

If PanelChooserTabControl.SelectedTab Is EditionTabPage Then
'The user canĀ“t leave
e.Cancel = True
End If


But I will have more TabPages and I want to make the code easy with Select Case

Dim TabPageActive As String = PanelChooserTabControl.SelectedTab.ToString
Select Case TabPageActive
Case "TabPage:{SelectionTabPage}"
'What I want
Case "EditionTabPage"
'What I want
End Select


But the TabPageActive variable is loaded with something like
TabPage:{SelectionTabPage}

and not only "SelectionTabPage". Even using TabPage:{SelectionTabPage} as the Case variable (like the example code) is not working.

Do I need to make another string conversion or trim?

Answer

You can try something like:

Select Case True
  Case PanelChooserTabControl.SelectedTab Is SelectionTabPage
  Case PanelChooserTabControl.SelectedTab Is EditionTabPage
  ...
End Select

or on tabPage index change save as an enum the page and use this enum in the case.

Comments