C# .NET - How to retrive which tab is currently selected in tab container
Asked By Sneha Deore on 18-May-09 06:52 AM
hi!
I m complete lost..how do i retrieve which tab is selected in tab Container
the code is below:-
if (tabId.TabIndex == 3)
{
//code is here
}
tabId is a id of tab Container
Santhosh N replied to Sneha Deore on 18-May-09 07:03 AM
You can make use of SelectedIndexChanged event of the Tab control and get the current selected index into a variable...
private void TabControl1_SelectedIndexChanged(Object sender, EventArgs e) {
globVar = TabControl1.SelectedIndex;
}
sorry but there so such Event in Tab Container
Sneha Deore replied to Santhosh N on 18-May-09 07:46 AM
hi!
I m Using TabContainer control and there is no suct Event for it...
Alice J replied to Sneha Deore on 18-May-09 07:48 AM
You can use TabControl.SelectedTab Property to identify the currently selected tab in the tab control.
Following is a sample code illustrating the use of TabControl.SelectedTab Property. You can modify this to suit your application.
using System.Drawing;
using System.Windows.Forms;
public class Form1 : Form
{
private TabControl tabControl1;
private TabPage tabPage1;
private TabPage tabPage2;
private void MyTabs()
{
this.tabControl1 = new TabControl();
this.tabPage1 = new TabPage();
this.tabPage2 = new TabPage();
this.tabControl1.Controls.AddRange(new Control[] {
this.tabPage1,
this.tabPage2});
this.tabControl1.Padding = new Point(15, 10);
this.tabControl1.Location = new Point(35, 25);
this.tabControl1.Size = new Size(220, 220);
// Selects tabPage2 using SelectedTab.
this.tabControl1.SelectedTab = tabPage2;
this.tabPage1.Text = "tabPage1";
this.tabPage2.Text = "tabPage2";
this.Size = new Size(300, 300);
this.Controls.AddRange(new Control[] {
this.tabControl1});
}
public Form1()
{
MyTabs();
}
static void Main()
{
Application.Run(new Form1());
}
}
Re
Ravenet Rasaiyah replied to Sneha Deore on 18-May-09 07:49 AM
Hi
You can write code like this way
private void tabControl1_SelectedIndexChanged(object sender,
int index= tabControl1.SelectedIndex
|
}
All tab properties handling
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c93c.aspx
thank yoiu
Santhosh N replied to Sneha Deore on 18-May-09 08:14 AM
Sorry, I was thinking that you are using TabControl of winforms..
But, other wise if you are looking at Ajax TabContainer control, and if you are looking a way to get the active tab, then you can do in this way..
http://www.unidevtech.com/index.php/2009/05/maintaining-the-active-tab-in-tabcontainer-control/
you can try using the ActiveTabIndex property
H K replied to Sneha Deore on 18-May-09 12:32 PM
you can get the active tab index by using the property TabCtrl.ActiveTabIndex
if (tabId.ActiveTabIndex == 3)
{
//code is here
}
Solution :: How to retrive which tab is currently selected in tab container
DC RC replied to Sneha Deore on 18-May-09 01:16 PM
Hello,
try this link,
http://www.asp.net/Ajax/Ajaxcontroltoolkit/samples/Tabs/Tabs.aspx
in above link there is detail about Active tab index and Active tab changed
hope this help
Thanks
i dont want to use Java scripit
Sneha Deore replied to H K on 19-May-09 02:30 AM
hi...
can u plz sort out my this to problem..
1. when the data in fist tab are saved i need secont tab to be opened
2. and can u tell which event is beign called when tab are change..
i dont want to use Java script (as Client does not want it ) :-(