473,378 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Common method of using tab control?

I have a tab control with seven tabs. I need to do certain things when
a user clicks each tab. I'm doing this:

private void tabControl1_Click(object sender, EventArgs e)
{
if(tabControl1.SelectedIndex == 0)
{...do something...}
else if (tabControl1.SelectedIndex == 6)
{...do something...}
.....
}

and so on for all tabs. That or switches will work but isn't very
intuitive. Is there some other common way of doing this?

Thanks,
Brett

Jan 18 '06 #1
3 2976
Brett,

That's really the only way of doing it, really. You could perform an if
statement on the text of the tab, assuming that it is unique.

Is there some other way you were hoping to be able to do it?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
I have a tab control with seven tabs. I need to do certain things when
a user clicks each tab. I'm doing this:

private void tabControl1_Click(object sender, EventArgs e)
{
if(tabControl1.SelectedIndex == 0)
{...do something...}
else if (tabControl1.SelectedIndex == 6)
{...do something...}
....
}

and so on for all tabs. That or switches will work but isn't very
intuitive. Is there some other common way of doing this?

Thanks,
Brett

Jan 18 '06 #2
I wasn't sure what else may be available for the tabcontrol in this
scenario. I just don't see all of those if statements or their
cousins, switches, as an elegant solution. That's all.

Thanks,
Brett

Jan 18 '06 #3
You can use the TabControl's SelectedIndexChanged event, or the TabPage's
Click event.
I supose you can use somthing like:

private void tabControl1_SelectedIndexChanged(
object sender,
System.EventArgs e)
{
if (this.tabControl1.SelectedTab.Equals(this.tabPage1 ))
{
// do somthing...
}
else if (this.tabControl1.SelectedTab.Equals(this.tabPage2 ))
{
// do somthing...
}
}

Mihaly

"Brett Romero" wrote:
I have a tab control with seven tabs. I need to do certain things when
a user clicks each tab. I'm doing this:

private void tabControl1_Click(object sender, EventArgs e)
{
if(tabControl1.SelectedIndex == 0)
{...do something...}
else if (tabControl1.SelectedIndex == 6)
{...do something...}
.....
}

and so on for all tabs. That or switches will work but isn't very
intuitive. Is there some other common way of doing this?

Thanks,
Brett

Jan 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: S.W. Rasmussen | last post by:
With the risk of being accused of multi-posting I would like to draw the attention to a serious visual basic/windows issue discussed in the microsoft.public.vb.bugs newsgroup. As pointed out below...
1
by: K Gibbs | last post by:
Lets say I have two threads which "communicate" via a shared object (passed to them as a reference when they are created). The shared object is primarily composed of getters and setters. In quite...
7
by: Byron | last post by:
I have several user controls that have a few methods in common, such LoadFromForm() which populates an object from controls on the form. I want to call that method from the form in which the...
3
by: Frank Esser | last post by:
Hi ! I have several buttons and a common click event for all of them. How can I get the reference to the clicked control in a switch? This does not work: private void Button_Click(object...
11
by: stax | last post by:
Hi, Assuming having a method that calls another method which also calls other methods and so on having a long winded tree of methods. What do I do in case it turns out everything has to be...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
2
by: letmefly | last post by:
Hello , i use a method that has a Control as parameter ex. public static void Method(Control c) This control can be RadioButtonList, DropDownList , CheckBoxList , ListBox ..All of these...
1
by: sirimanna | last post by:
I want to know how can i open some text file data using microsoft common dialog control.6 I know how to save text data using microsoft common dialog control.6 code are here, ...
1
by: Ben | last post by:
Hi. Can anyone decribe a good method to share Common classes between projects while using source control? I used to just point everything to one directory... but started using SourceSafe...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.