How can cancel clicked page and stay to page I was before in "NavigationView"?

2 Answers 146 Views
Form NavigationView PageView
Simos Sigma
Top achievements
Rank 2
Iron
Iron
Iron
Simos Sigma asked on 23 Aug 2022, 02:35 PM

Hello community!!!

I am working on a small project with a "RadForm" which contains a "RadPageView". This "RadPageView" has been set to "NavigationView" mode. It contains four pages (RadPageViewPage) and one of them is "Settings" page.

What I am trying to do is...

When user makes any change on settings page and try to change page, takes a message. If user choose to save changes, program saves changes. Else just goes to clicked page.

My problem is...

As you can see in my code, I want user to remain in settings page when choose to save changes ( Main_radPageView.SelectedPage = Settings_radPageViewPage; ). In my code, program saves the changes but it goes to the page which clicked before!!!

        private void Settings_radPageViewPage_VisibleChanged(object sender, EventArgs e)
        {
            if (!Settings_And_SettingsFields_AreEqual())
            {
                DialogResult Dialog_Result = RadMessageBox.Show(this, "You have make changes on settings. Do you want to save them?", "Message", MessageBoxButtons.YesNo, RadMessageIcon.Info);
                if (Dialog_Result == DialogResult.Yes)
                {
                    // Code...
                    Main_radPageView.SelectedPage = Settings_radPageViewPage;
                }
                else
                {
                    // Code...
                }
            }
        }
Any idea how can I achieve that? Am I using the "correct" event (VisibleChanged)?

Thank you for your time!!!
Chris
Top achievements
Rank 2
Iron
commented on 23 Aug 2022, 05:38 PM

Maybe you can use this.


private void radPageView1_SelectedPageChanging(object sender, RadPageViewCancelEventArgs e)
{
       e.Cancel = true;
}
Kind Regards, Chris.

2 Answers, 1 is accepted

Sort by
1
Accepted
Chris
Top achievements
Rank 2
Iron
answered on 23 Aug 2022, 05:45 PM

Maybe you can use this.


private void radPageView1_SelectedPageChanging(object sender, RadPageViewCancelEventArgs e)
{
       e.Cancel = true;
}
Kind Regards, Chris.
Simos Sigma
Top achievements
Rank 2
Iron
Iron
Iron
commented on 24 Aug 2022, 08:33 AM

Thank you for you time Chris!!! Your solution is "working" but I have a problem... Please take a look on comments under Dess's answer!!!
1
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Aug 2022, 04:31 AM

Hello,

The provided solution by Chris is the appropriate way to stay on the same page and cancel the operation. Indeed, the SelectedPageChanging event allows you to control whether to proceed further to the new page or remain on the same page. Feel free to set the RadPageViewCancelEventArgs.Cancel argument to true if you want to restrict the selection changing. Thus, the content area will remain displaying the selected page.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Simos Sigma
Top achievements
Rank 2
Iron
Iron
Iron
commented on 24 Aug 2022, 08:29 AM

I used Chris example like this...

private void Main_radPageView_SelectedPageChanging(object sender, RadPageViewCancelEventArgs e)
{
    if (!Settings_And_SettingsFields_AreEqual() && Main_radPageView.SelectedPage == Settings_radPageViewPage )
    {
        DialogResult Dialog_Result = RadMessageBox.Show(this, "You have make changes on settings.\n\nDo you want to save them?", "Message", MessageBoxButtons.YesNo, RadMessageIcon.Info);
        if (Dialog_Result == DialogResult.Yes)
        {
            // Code...
            e.Cancel = true;
        }
        else
        {
            // Code...
        }
    }
}
But I have a problem... It works, but I also get this RadMessageBox even before my main form show-up!!!!!!

I added a Debug.WriteLine(Main_radPageView.SelectedPage); on my form's load event, so to see which page is the SelectedPage when my form loads and I got this into my output window...
RadPageViewPage [Settings]
RadPageViewPage [Home]
And I have set as DefaultPage the "Home" page in Main_radPageView properties, not the "Settings" page!!!

Any idea why is this happening?

Thank you for your time!!!
Chris
Top achievements
Rank 2
Iron
commented on 24 Aug 2022, 08:46 AM

Maybe you have the "Settings" page open in designer.
Then on formload it switches from "Settings" to "Home"
This causes the Main_radPageView_SelectedPageChanging event to fire. 

Kind Regards,
Chris.

 

Simos Sigma
Top achievements
Rank 2
Iron
Iron
Iron
commented on 24 Aug 2022, 08:56 AM | edited

@Chris: Yes you are right!!! I just realized that and I came back to write it here. Is there anything else we can to do about this? Except for click somewhere else in designer before start program? Because I tried to add Main_radPageView.SelectedPage = this.Home_radPageViewPage; under InitializeComponent(); but nothing...
Chris
Top achievements
Rank 2
Iron
commented on 24 Aug 2022, 09:14 AM

@Simos Sigma, you can disable the  Main_radPageView_SelectedPageChanging event.

After InitializeComponents();

Main_radPageView.SelectedPageChanging -= Main_radPageView_SelectedPageChanging;

then when the form is fully loaded (Form shown event) use

Main_radPageView.SelectedPageChanging += Main_radPageView_SelectedPageChanging;

to enable it again.

 Kind Regards,
Chris.

Simos Sigma
Top achievements
Rank 2
Iron
Iron
Iron
commented on 24 Aug 2022, 09:27 AM | edited

@Chris: Worked!!! Plus I had to remove this.Main_radPageView.SelectedPageChanging += new System.EventHandler<Telerik.WinControls.UI.RadPageViewCancelEventArgs>(this.Main_radPageView_SelectedPageChanging); from "Designer.cs". Thank you so much!!! :-)
Dess | Tech Support Engineer, Principal
Telerik team
commented on 26 Aug 2022, 10:20 AM

Hello, If you want to ensure that the form is started with a specific selected page, make sure that you set the RadPageView.SelectedPage property to the desired page in the form's constructor. However, it is necessary to subscribe to the SelectedPageChanging event at a later moment, e.g. the form's Load or Shown events.

Tags
Form NavigationView PageView
Asked by
Simos Sigma
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Chris
Top achievements
Rank 2
Iron
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or