tabs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On my form i have several tabs, how can i determine which tab is selected by
the user?
 
Assuming that you are referring to tabs of a TabControl, you have either
TabControl.SelecteIndex or TabControl.SelectedTab.

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
but with one of those 2 how can I determine which tab is selected?
example:
if the user clicks (selects) the tab that says cars, then i want to run the
car function, if they pick trucks, then run the truck function. I only want
the correct function to run when the user selects that tab
 
SelectedIndexChanged


Mike said:
but with one of those 2 how can I determine which tab is selected?
example:
if the user clicks (selects) the tab that says cars, then i want to run
the
car function, if they pick trucks, then run the truck function. I only
want
the correct function to run when the user selects that tab
 
I never used the tabs before so I apologize if i sound like an idiot. Using
SelectIndexChanged, how can i determine which tab was selected?

Do i use the index number, or can i use the Text on the tab? do you have a
code snippet i could look at?
 
Ok, you REALLY need to read the documentation now. I'll give this one, but
please, use the help files. In visual studio, there is a Search panel for
the .Net documentation. Type TabControl Class into the search criteria,
then in the help file, loo at the link at the bottom that says TabControl
Members, then read them all one by one until you find what you are looking
for

SelectedTab

JIM
 
Mike,

What james is saying is that in order to achieve what you want you need
to do two things.

First, as Carlos pointed out, the TabControl object has two properties,
SelectedIndex, which returns the tab's index (in order 0, 1, 2, ...
from first to last), and SelectedTab, which returns the selected
TabPage itself as an object.

However, that's not enough to do what you want. You want to react to a
_change_ in the currently selected tab page, so just knowing the
current page is insufficient. So, you need events. The event
SelectedIndexChanged of the TabControl will be raised whenever the
selected tab page changes.

So, you need to hook up an event handler to SelectedIndexChanged:

myTabControl.SelectedIndexChanged += new
EventHandler(myTabContol_SelectedIndexChanged);

then, inside your myTabContol_SelectedIndexChanged method, you can
check SelectedIndex or SelectedTab to see what is the new tab page that
the user just selected.
 
Back
Top