Force Tab selection using Tab Strip 
Author Message
 Force Tab selection using Tab Strip

Using VB6's Tab Strip control I've always been able to force a tab selected
using this code:

me.tbsTest.SelectedItem = "Test Caption"

Provided, of course, a member of the Tab collection has a Tab named "Test
Caption" then this tab would be selected.

Is this the proper way to select a specific tab in a collection? Is there
another way?

BB



Sat, 26 Nov 2005 03:01:44 GMT  
 Force Tab selection using Tab Strip
Quote:
> me.tbsTest.SelectedItem = "Test Caption"

That line of code sets the caption of the current tab here... one more reason to *never
rely on default properties*

This code works... I setup a tabstrip with 2 tabs. Their Key property set to "TabOne" and
"TabTwo"
'========
Option Explicit

Private Sub Command1_Click()
   'This selects tab 2
   TabStrip1.Tabs("TabTwo").Selected = True
End Sub

Private Sub Command2_Click()
   'This sets the caption of the selected tab. Not very useful at all (for switching tabs
anyway)
   TabStrip1.SelectedItem = "TabOne"
End Sub

Private Sub Command3_Click()
   'This code uses something close to the code you posted (and works)
   Set TabStrip1.SelectedItem = TabStrip1.Tabs("TabOne")
End Sub
'========

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep it in the groups..

Quote:

> Using VB6's Tab Strip control I've always been able to force a tab selected
> using this code:

> me.tbsTest.SelectedItem = "Test Caption"

> Provided, of course, a member of the Tab collection has a Tab named "Test
> Caption" then this tab would be selected.

> Is this the proper way to select a specific tab in a collection? Is there
> another way?

> BB



Sat, 26 Nov 2005 03:11:28 GMT  
 Force Tab selection using Tab Strip
Thanks Ken.

Your Command3 example is how I've done it in the past; substituting an
Integer value for the string "TabOne". This time I simply tried to use the
caption value after capturing it elsewhere. But I'm still confused. I mean,
isn't TabStrip1.Tabs("TabOne") returning a string? And if so, why would my
original post fail? It uses a string ("Test Caption") to set the .SelectItem
property.

BB


Quote:
> > me.tbsTest.SelectedItem = "Test Caption"
> That line of code sets the caption of the current tab here... one more
reason to *never
> rely on default properties*

> This code works... I setup a tabstrip with 2 tabs. Their Key property set
to "TabOne" and
> "TabTwo"
> '========
> Option Explicit

> Private Sub Command1_Click()
>    'This selects tab 2
>    TabStrip1.Tabs("TabTwo").Selected = True
> End Sub

> Private Sub Command2_Click()
>    'This sets the caption of the selected tab. Not very useful at all (for
switching tabs
> anyway)
>    TabStrip1.SelectedItem = "TabOne"
> End Sub

> Private Sub Command3_Click()
>    'This code uses something close to the code you posted (and works)
>    Set TabStrip1.SelectedItem = TabStrip1.Tabs("TabOne")
> End Sub
> '========

> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Please keep it in the groups..




- Show quoted text -

Quote:
> > Using VB6's Tab Strip control I've always been able to force a tab
selected
> > using this code:

> > me.tbsTest.SelectedItem = "Test Caption"

> > Provided, of course, a member of the Tab collection has a Tab named
"Test
> > Caption" then this tab would be selected.

> > Is this the proper way to select a specific tab in a collection? Is
there
> > another way?

> > BB



Sat, 26 Nov 2005 03:28:03 GMT  
 Force Tab selection using Tab Strip

Quote:

> Thanks Ken.

> Your Command3 example is how I've done it in the past; substituting an
> Integer value for the string "TabOne". This time I simply tried to use the
> caption value after capturing it elsewhere. But I'm still confused. I mean,
> isn't TabStrip1.Tabs("TabOne") returning a string? And if so, why would my
> original post fail? It uses a string ("Test Caption") to set the .SelectItem
> property.

> BB

Actually, what your code was doing (here anyway... VB6/SP5) was setting the caption
property of the current tab. Not selecting the tab itself.

'=======
Private Sub Command1_Click()
   'The SelectedItem points to a member of the Tabs collection
   'The defualt property of a Tab object (even though it doesn't show in the object
browser) is the Caption property
   'so, this code will display the Caption of the currently selected tab in the debug
window.
   Debug.Print TabStrip1.SelectedItem
End Sub
'=======

Quote:
> isn't TabStrip1.Tabs("TabOne") returning a string

No...

Set obj = TabStrip1.Tabs("TabOne") 'would return a member of the Tabs collection whos Key
= "TabOne" (doesn't work with captions at all)

The reason that it may seem to return a string is due to that darned Default property
(Caption).

That's similar to....

MyStringVar = Text1

which is equally bad (imo) because it relies on "Text" to be the default property of the
TextBox.

MyStringVar = Text1.Text 'would be my preferred way to code it. Mostly because both of the
lines below will "work" but they do completely different things

Set MyObjectVar = Text1 'passes a reference to a control named Text1 to the object
variable MyObjectVar
...and...
MyStringVar = Text1 'passes the contents of a control named Text1 to a string variable
called MyStringVar

in the sample above, since the names are "plain as day", it's not so bad (still wouldn't
do it though) but when the variable names aren't so descriptive, bugs tend to rear their
ugly head when you're not expecting them... and since the lines "look" like they should
work, these bugs are usually hard to find and kill. That problem goes away when explicit
property names are used.

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep it in the groups..



Sat, 26 Nov 2005 04:14:11 GMT  
 Force Tab selection using Tab Strip
Thanks Ken. Sage advice.

BB



Quote:
> > Thanks Ken.

> > Your Command3 example is how I've done it in the past; substituting an
> > Integer value for the string "TabOne". This time I simply tried to use
the
> > caption value after capturing it elsewhere. But I'm still confused. I
mean,
> > isn't TabStrip1.Tabs("TabOne") returning a string? And if so, why would
my
> > original post fail? It uses a string ("Test Caption") to set the
.SelectItem
> > property.

> > BB

> Actually, what your code was doing (here anyway... VB6/SP5) was setting
the caption
> property of the current tab. Not selecting the tab itself.

> '=======
> Private Sub Command1_Click()
>    'The SelectedItem points to a member of the Tabs collection
>    'The defualt property of a Tab object (even though it doesn't show in
the object
> browser) is the Caption property
>    'so, this code will display the Caption of the currently selected tab
in the debug
> window.
>    Debug.Print TabStrip1.SelectedItem
> End Sub
> '=======

> > isn't TabStrip1.Tabs("TabOne") returning a string
> No...

> Set obj = TabStrip1.Tabs("TabOne") 'would return a member of the Tabs
collection whos Key
> = "TabOne" (doesn't work with captions at all)

> The reason that it may seem to return a string is due to that darned
Default property
> (Caption).

> That's similar to....

> MyStringVar = Text1

> which is equally bad (imo) because it relies on "Text" to be the default
property of the
> TextBox.

> MyStringVar = Text1.Text 'would be my preferred way to code it. Mostly
because both of the
> lines below will "work" but they do completely different things

> Set MyObjectVar = Text1 'passes a reference to a control named Text1 to
the object
> variable MyObjectVar
> ...and...
> MyStringVar = Text1 'passes the contents of a control named Text1 to a
string variable
> called MyStringVar

> in the sample above, since the names are "plain as day", it's not so bad
(still wouldn't
> do it though) but when the variable names aren't so descriptive, bugs tend
to rear their
> ugly head when you're not expecting them... and since the lines "look"
like they should
> work, these bugs are usually hard to find and kill. That problem goes away
when explicit
> property names are used.

> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Please keep it in the groups..



Sat, 26 Nov 2005 05:42:50 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. tab or tab strip control

2. Selecting tab on tab strip

3. Newbie: How to select a tab on a tab strip

4. diabling a tab in a tab strip

5. Colors in tab-strip en tab-control?

6. Tabs: Disabeling the selection of tabs

7. Using resource file to load Tab strip images

8. Using ActiveX Tab Strip Control in HTML

9. Using resource file to load Tab strip images

10. Using ActiveX Tab Strip Control in HTML

11. Tab order when using Tab control

12. TAB and Shift+TAB using API

 

 
Powered by phpBB® Forum Software