RichRibbonBar Error on Save

2 posts, 0 answers
  1. Jeff
    Jeff avatar
    48 posts
    Member since:
    Apr 2012

    Posted 02 Jul 2013 Link to this post

    Using the RichRibbonBar, I get an error any time I use the "Save" button. I don't get the error when using "Save As". This happens when using the QuickAccessToolbar or the File menu.

    The error is "Object reference not set to an instance of an object." in this Sub on the line "Me.SaveDocument(button.Tag.ToString())"
    Private Sub buttonSave_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim button As RadButton = TryCast(sender, RadButton)
        Me.BackstageControl.HidePopup()
        Me.SaveDocument(button.Tag.ToString())
    End Sub

  2. George
    Admin
    George avatar
    500 posts

    Posted 04 Jul 2013 Link to this post

    Hello Jeff,

    Thank you for contacting us.

    The exception you are seeing is due to inappropriate cast. When trying to cast the sender as a RadButton the cast fails and returns null, which causes the exception. The right cast in this situation would be to RadButtonElement. Also it's always good to check for null values if possible in order to prevent such exceptions. Please take a look at the code below.
    Private Sub buttonSave_Click(sender As Object, e As EventArgs)
        Dim button As RadButtonElement = TryCast(sender, RadButtonElement)
        If button IsNot Nothing Then
            Me.BackstageControl.HidePopup()
            Me.SaveDocument(button.Tag.ToString())
        End If
    End Sub

    I hope this helps.
     
    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top