SelectedPage Events question

5 posts, 0 answers
  1. Bob
    Bob avatar
    41 posts
    Member since:
    Mar 2012

    Posted 30 May 2012 Link to this post

    I'm trying to add and remove handlers as a page is loaded and unloaded using the RAdPageVIew Control.
    I am subscribing to both SelectedPageChanging and SelectedPageChanged events to monitor when appropriate pages load, however I cannot seem to retain the previous page in order to know which handlers to remove.  I also can't seem to get the PageIndexChanged event to fire -at all.

    I'm using VB.net with the latest build of WinForm controls.

    Can I get a sort example to determine which page is closing and which one is opening.

    I appreciate the help.
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 31 May 2012 Link to this post

    Hello Bob,

    Thank you for writing.

    To achieve your requirement, you can subscribe to the SelectedPageChanging event. Its event arguments provide the page that is about to be selected and you can get the old selected page from the SelectedPage property of RadPageView since at the moment of firing the SelectedPageChanging event the SelectedPage has not yet been changed. The following code snippet demonstrates this:
    private void radPageView1_SelectedPageChanging(object sender, RadPageViewCancelEventArgs e)
    {
        Console.WriteLine("Changing from " + this.radPageView1.SelectedPage + " to " + e.Page);
    }

    As to the PageIndexChanged event, this event is fired when a specific page changes its position amongst the other pages. It should not fire when just changing the selected page.

    I hope this will help you.

    A bit off topic, I would like to remind you that your trial support package has expired. If you would e to continue receiving support from us, you will have to consider a purchase of some of the licenses that we offer. At this link - http://www.telerik.com/purchase.aspx - you can find the available options. These licenses come with Dev priority support where the tickets should be answered in a guaranteed period of time. Shortly said, we will provide you with quicker responses.

    Feel free to ask if you have any additional questions.

    Kind regards,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bob
    Bob avatar
    41 posts
    Member since:
    Mar 2012

    Posted 31 May 2012 Link to this post

    Thank you for the response.

    I have attemped to perform this operation in VB and I am not getting the same results.  In-fact, I am receiving some errors.  I have tried the code in c# and it did work, but I can't rewrite the existing app into c# at this time.

    In the various ways I have attempted to write the code in VB I cannot appear to get any information back without receiving some sort of error.  Can I get a VB sample on how to catch the name of the current page and the new page so I can write a case statement to perform some event handling.

    I know this is a simple event, but I'm having difficulties using this event.

    Your help is appreciated.

    As for the other item, I have put a request in with my company, we'll see if they approve it.

    Thanks
  5. Bob
    Bob avatar
    41 posts
    Member since:
    Mar 2012

    Posted 31 May 2012 Link to this post

    OK - after I clicked the submit button, I dug a little deeper into documentation and trial and error and I think I got it to work in VB.

    I had to create a new variable of type RadPageViewPage, then assign the value to the SelectedPage.  That allowed me to get the properties of the page, while e.page.name provides me the name of the page changing too.

    A little confusing at first, but I think I got it.

    Thanks for the help.
    Bob
  6. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 01 Jun 2012 Link to this post

    Hi Bob,

    I am glad that you have managed to sort this out. Nevertheless, here are some thoughts about this.

    I think that the problem with VB is that it handles the events in a bit different manner and also requires you to call the ToString method of the pages. In VB, when you use the Handles clause, the event is hooked at an earlier moment and you might get it fired with some of the two properties equal to Nothing which causes a reference exception. To avoid the null reference error, you can use the Convert.ToString method:
    Private Sub RadPageView1_SelectedPageChanging(sender As System.Object, e As Telerik.WinControls.UI.RadPageViewCancelEventArgs) Handles RadPageView1.SelectedPageChanging
        RadMessageBox.Show("Changing from " & Convert.ToString(Me.RadPageView1.SelectedPage) & " to " & Convert.ToString(e.Page))
    End Sub

    I hope you find this useful.

    Greetings,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready