views:

158

answers:

2

I have a form with a tabcontrol and 4 tabs. I want to open a form with showdialog in a predetermined tab.

I've tried

    OptionsForm.OPTS_TabControl1.SelectTab(1)
    OptionsForm.OPTS_TabControl1.ShowDialog()

but it didn't work.

Any help? thanks

+1  A: 

Hello Ellome.

First Kudos for using Stackoverflow. It shows you paid attention to class =D

regarding your question, that piece of code you showed should be working. You should provide the actual error so we can try to figure out.

Does OptionsForm refer to the class or an object of a class you created?

Anyways, try to create an object of the form and then set the starting tab, like this:

Dim OptionsObject As New OptionsForm
OptionsObject.OPTS_TabControl1.SelectTab(1)
OptionsObject.OPTS_TabControl1.ShowDialog()

Another solution might be Overloading the Showdialog method, although it seems kind of an overshot.

Here's how: Inside your OptionsForm Code:

Public Overloads Sub Showdialog(ByRef TabNumber As Integer)

OPTS_TabControl1.SelectTab(TabNumber)

Return MyBase.ShowDialog()

then call the form using

optionsform.showdialog(1)

Note: Overloading is basically creating another instance of a subrotine that accepts different arguments. read the pages 342-358 of the manual if you wish to know more.

Tivie
it worked with the first solution you gave. thanks!
Ellome
+1  A: 

Since you are getting a NullReferenceException, you should separate out the call to see where the null object is. Is the tab control null?.

Zach Johnson
if I comment the first line: OptionsForm.OPTS_TabControl1.SelectTab(1)it opens ok (in the wrong tab of course).If I uncomment, it give me the NullExceptionError in that line.
Ellome