hi all,
i have forms with 2 or more tab pages in them.
i would like to know how can we open or display "tabpage1", when we click a button "btn"in "tabpage2"...

please help me..i need a reply soon..
thanks all..

Dani AI

Generated

Good catch by — switching the TabControl selection from your button click is the right approach. A few practical notes and small improvements that help this pattern work well in real apps.

Keep UI changes encapsulated. Put the tab-switch logic on the form that owns the TabControl and call a small public method from other controls or handlers. That lets a button inside a user control or another class ask the form to switch tabs without reaching into the form's internals.

Example of an encapsulating helper on the form:

public void SwitchToTabIndex(int index)
{
    tabControl1.SelectedIndex = index;
}

Common problems and fixes: confirm the button's Click handler is actually wired; confirm the target TabPage is present in the TabControl.TabPages collection (if you removed/hid it earlier you must add it back); if the request to switch comes from a background thread, marshal it to the UI thread with Invoke/BeginInvoke; if switching from another form, call a public method on the owning form rather than creating a new form instance. After switching, call Focus on a control inside the newly selected tab if you need keyboard focus or to trigger layout.

If this is an ASP.NET scenario (Tag indicates both WinForms and web), server-side tab controls use their own API to set the active tab or active index, or you can switch tabs client-side with JavaScript for a smoother UX. These alternatives keep the same pattern: change the tab control’s active selection from code that runs where the control lives.

Recommended Answers

All 2 Replies

In the Button's Click event:

tabControl1.SelectedTab = tabPage2

thanks a looooooooooootttttttt...that was easy :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.