Hi, I have a TabControl with two TabPages and I was wondering what is the best way to test which tab is currently displayed? I'm not sure why I can't figure this one out...
Thanks. This is kinda ugly but it works.
Cody C
2009-09-24 14:38:53
+1
A:
Assuming this is a WPF application, make sure that each TabItem has an Name.
Then it's just a matter of checking.
if tabItem1.IsSelected = true then
' Do Something
else if tabItem2.IsSelected = true then
' Do Something
end if
Stephen Wrighton
2009-09-24 14:33:03
Yeah, this is how I was figuring how to do it but there's no members called IsSelected or Selected, I guess you have to use SelectedTab, kinda ugly but it works.
Cody C
2009-09-24 14:37:44
doing a bit more lokoing into this, apparently the IsSelected is only available for the WPF TabItem class. The WinForms one doesn't support the IsSelected property.
Stephen Wrighton
2009-09-24 15:06:35
A:
If you use .Net 3.5, you can create a IsSelected method as an extension method if you wish:
Public Module TabControlExtensions
<Extension()> _
Public Function IsSelected(ByVal tabPage As TabPage) As Boolean
Dim tabControl = CType(tabPage.Parent, TabControl)
Return (tabControl.SelectedTab Is tabPage)
End Function
End Module
Meta-Knight
2009-09-25 15:05:12