What is the easyest way to find which tab is on. I want to show some data when i click on tabpage2 or some other tabpage. I did it like this but is not good solution:
private int findTabPage { get; set; }
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedTab == tabPage1)
findTabPage = 1;
if (tabControl1.SelectedTab == tabPage2)
findTabPage = 2;
}
and for displaying data:
if (findTabPage == 1)
{ some code here }
if (findTabPage == 2)
{ some code here }
Is there any other solution for example like this?
Use
tabControl1.SelectedIndex;
This will give you selected tab index which will start from 0 and go till 1 less then the total count of your tabs
Use it like this
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
switch(tabControl1.SelectedIndex)
{
case 0:
{ some code here }
break;
case 1:
{ some code here }
break;
}
}
This is a much better approach.
private int CurrentTabPage { get; set; }
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
CurrentTabPage = tabControl1.SelectedIndex;
}
In this way every time the tabindex is changed, our required CurrentTabPage would automatically updated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With