Events for PageChange

Wizard for Windows Forms Forum

Posted 17 years ago by Logicway
Avatar
I have read the forums and the documentation, but would like to be sure which events to use for (cancelling) page changes.

I want to:
- programatically change page sequence
- perform validation before page change
- cancel page change if not validated
- do something if validated

Which events should I use for this?

Can I use the [pagename]-nextbuttonclick-event for all cases?
Is it adviced to use the [pagename]-nextbuttonclick-event only for page sequence changing?
Is it also adviced to use the selectionchanging-event for validation before page change?
What exactly cancels the e.Cancel for the nextbuttonclick-event and the selectionchanging-event? Is it the same for both, or is it different?
Why isn't there a selectionchanging-event for wizardpage class?

Comments (9)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Let me answer your questions....

NextButtonClick will fire only when you press the Next button. If that is the only time you ever will cancel page changes then that is a good place to validate/cancel the page change.

SelectionChanging happens after the button click events if the button click events aren't cancelled. e.Cancel in them do the same thing, just the button one occurs first and the SelectionChanging can happen for any page change, not just next button clicks.

The selection change is related to the Wizard control's selection so we just never added one to the pages.


Actipro Software Support

Posted 17 years ago by Logicway
Avatar
Thanks for your answers.

Will the SelectionChanging/SelectionChanged events added to the pages in a future release?
This will make it easier to handle pagesequencing and pagecancelling separatly.
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Possibly. If it's something you would require immediately, you could always contract us to do it (http://www.actiprosoftware.com/Purchase/ConsultingServices.aspx). It would probably only take 1-2 hours.


Actipro Software Support

Posted 17 years ago by Logicway
Avatar
Thanks for your offer, but I will wait till it's implemented.

But I am still stuck with "e.Cancel".
Is it right that if I do this:
private void wizardpage1_NextButtonClick(object sender, ActiproSoftware.Wizard.WizardPageCancelEventArgs e)
        {
            if (this.combobox1.SelectedIndex == -1)
            {
                e.Cancel = true;
            }
        }
only page change will be cancelled.
But if I do this:
private void wizardpage1_NextButtonClick(object sender, ActiproSoftware.Wizard.WizardPageCancelEventArgs e)
        {
            if (this.combobox1.SelectedIndex == -1)
            {
                e.Cancel = true;
                this.Wizard.SelectedPage = wizardpage3;
            }
        }
the page will change to wizardpage3.

So "e.Cancel = true" on its own will cancel pagechange, but "e.Cancel = true" followed by "this.Wizard.SelectedPage = pagename" will not cancel pagechange, but will cancel the default pageseqeuence and change the page as set.

Am I right?
Somehow it isn't logical.
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, you are correct on both. e.Cancel tells us to cancel the default page change that will occur. By doing that AND by you specifying a new selected page, you are forcing it to go to the page of your choosing.


Actipro Software Support

Posted 16 years ago by Logicway
Avatar
How can I make the NextButtonClick-event go directly to the next page?

I am doing some time-consuming things in the NextButtonClick-event, even using a backgroundworker does not show the next page, until the time-consuming things finishes. I want it to show the next page immediatly, and perform all the action on the new page.

Something like this:

private void wizardPage1_NextButtonClick(object sender, ActiproSoftware.Wizard.WizardPageCancelEventArgs e)
{
    if (PageIsValid)
    {
        e.Page.Select(); //show next page
        //perform long running actions on next page
    }
    else
    {
        e.Cancel = true;
    }
}
I tried to use "e.Canel = false;" or "e.Page.Select();"

The SelectionChanging and SelectionChanged events are not suitable for me.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
When doing time consuming process you should definitely put the time consuming code in a BackgroundWorker so that it executes in a separate thread and calls back when complete. So are you saying you already did do this and put your processing code totally within a BackgroundWorker? If so I would think that it would allow the UI to display.


Actipro Software Support

Posted 16 years ago by Logicway
Avatar
Yes, I indeed put the time consuming code in a BackgroundWorker, but still the new page is not displayed, until all code finishes.

I now used the SelectionChanged event, and used some boolean-values to execute the code only once, and it is working.

But still, this would be a point of improvement. Maybe you should check this.
Also I am still missing the SelectionChanging and SelectionChanged events for the pages. And why doesn't the SelectionChanged event have pagecancel-events?
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes this is a good suggestion and perhaps we will add this sort of thing for the next major version. We did this in our newer Wizard product for WPF, where each page has its own set of selecting/ed events, etc. as well and each "ing" event lets you cancel the event.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.