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. Image for the cookie policy date
close icon

TabControlExt - tab changing

Does anyone know how I can consume and, if need be, cancel the change event of the current tab before it changes? Thanks!

6 Replies

AS Arun Srinivasan Syncfusion Team September 3, 2003 11:37 AM UTC

Hi Paul You can listen to the Validating Event of the current tab and cancel or invalidate it based on what you want to do, to do what you are looking for. Arun > Does anyone know how I can consume and, if need be, cancel the change event of the current tab before it changes? > > Thanks!


PL Paul Laudeman September 3, 2003 12:33 PM UTC

Unfortunlatey, that won't work for my purposes. On my TabPageExt I have a user control that contains a grid and another user control that we use to navigate between the tabs. The only time I can get the validating or validated events for the tab page to fire is when I click on another tab. If I click on a control within the tab that causes the current tab to be changed, the validating events won't fire. > Hi Paul > You can listen to the Validating Event of the current tab and cancel or invalidate it based on what you want to do, to do what you are looking for. > > Arun > > > > > Does anyone know how I can consume and, if need be, cancel the change event of the current tab before it changes? > > > > Thanks! >


RP Ramesh Praveen Syncfusion Team September 3, 2003 03:47 PM UTC

Paul, Yes, the selected tab can still be changed programatically. But, that chould easily be worked around by simply calling the Validate method on the container control, before changing the selected index. Something like this: bool validated = tabControl.GetContainerControl().Validate(); if(validated) // go ahead and change the selected tab else // do not switch the tab. Do let us know if this will work for you. Regards, -Praveen


PL Paul Laudeman September 4, 2003 10:14 AM UTC

Hi Praveen, Thanks for your reply. When I try to access the container control for either the tabpage or the tabstrip control itself, I get a reference to the form that contains the tabstrip control, which isn't what I really need. My solution to my problem was to modify the source for TabPageExt control and add an event called SelectedIndexChanging. This way, I could add an event handler to that event and, if I chose to, I could cancel the event and prevent the tab from ever changing. The problem was that I needed to handle the tab index change that could occur from either clicking another tab or by programmatically selecting another tab through code. -Paul > Paul, > > Yes, the selected tab can still be changed programatically. But, that chould easily be worked around by simply calling the Validate method on the container control, before changing the selected index. Something like this: > > bool validated = tabControl.GetContainerControl().Validate(); > if(validated) > // go ahead and change the selected tab > else > // do not switch the tab. > > Do let us know if this will work for you. > > Regards, > -Praveen >


RP Ramesh Praveen Syncfusion Team September 4, 2003 11:18 AM UTC

Paul, I just wanted to clarify a lit bit more. Ok, the logic I suggested to "validate" the current tab page didn't work for you. But, whatever logic you use in the new SelectedIndexChanging event to "validate", can you not use that same logic BEFORE setting a new SelectedIndex programatically? Regards, Praveen


PL Paul Laudeman September 4, 2003 02:25 PM UTC

Yes, that would work if I knew ahead of time what validation routines to run before changing the selcted index programmatically. However, the control we developed to do the programmatic changing is designed to work with any tab page, without regard to specific content. Ideally, when we programmatically change the selected index it would fire the validating events for the TabPage (which would recursively call the validating events of all controls on that page), and then I could just add an event handler in my user control to handle the validating event. Since that wasn't possible, I thought adding a SelectedIndexChanging event would be another way to meet our needs. One other option, along the lines you of what you suggested, might be to loop through all the controls on a TabPage and see if they implemented a method to do custom validation and call that before programmatically changing the selected index. -Paul > Paul, > > I just wanted to clarify a lit bit more. > > Ok, the logic I suggested to "validate" the current tab page didn't work for you. But, whatever logic you use in the new SelectedIndexChanging event to "validate", can you not use that same logic BEFORE setting a new SelectedIndex programatically? > > Regards, > Praveen

Loader.
Live Chat Icon For mobile
Up arrow icon