This is a migrated thread and some comments may be shown as answers.

RichRibbonBar Error on Save

1 Answer 73 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 03 Jul 2013, 02:52 AM
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

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 04 Jul 2013, 12:33 PM
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 >>
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Jeff
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or