We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

TabControl tell if tab changes by user click or programmatically

Thread ID:





93158 Feb 26,2010 12:30 PM Mar 1,2010 06:55 AM Windows Forms 1
Tags: Tools
Jon Zucker
Asked On February 26, 2010 12:30 PM

When using a TabControlAdv, we allow the user to select a tab. We perform some other actions when the user selects a tab. Also, we sometimes programmatically select a tab. When that happens, we need different things to happen than when a user clicks on a tab (and, also, we don't want an infinite loop).

Is there a way to tell the difference between having a user select a new tab and changing a selected tab programmatically? I've been using the SelectedIndexChanging event to catch when the user selects a new tab, but that means I have to keep disabling and enabling the event handler when I programmatically change the tab.

Rajasekar B [Syncfusion]
Replied On March 1, 2010 06:55 AM


In SelectedIndexChanged event,you can find whether the tab is selected by mouse or through code using the below workaround:

int i = this.tabControlAdv1.Renderer.HitTestTabs(this.tabControlAdv1.PointToClient(MousePosition), false);

This will return selected index. If the value of i is -1 then it indicates it is selected through code. If it returns exact selected index then it is selected by mouse.

Please let me know if this helps you.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.