Null reference exception when Printing

5 posts, 1 answers
  1. Dinesh
    Dinesh avatar
    3 posts
    Member since:
    May 2012

    Posted 16 May 2012 Link to this post

    Hi,

    I have a problem when i m trying printing my Document in RadRichTextBox.

    We have a requirement to print RADGrid data including subgrids. So we have created a RADDocument for the corresponding RadGrid and assigned it to RADRichTextBox.Document. But when we tried to execute RADRichTextBox.Print(PrintSettings) statement we are getting facing the below error:
    " at Telerik.Windows.Controls.RadRichTextBox.Print(PrintSettings printSettings)
       at Telerik.Windows.RadRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
       at Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
       at Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
       at Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
       at Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
       at Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
       at Telerik.Windows.Controls.RadMenuItem.OnClickImpl()
       at Telerik.Windows.Controls.RadMenuItem.OnClick()
       at Telerik.Windows.Controls.RadMenuItem.ClickItem()
       at Telerik.Windows.Controls.RadMenuItem.HandleMouseUp()
       at Telerik.Windows.Controls.RadMenuItem.OnMouseLeftButtonUp(MouseButtonEventArgs e)"

     I Have checked, the document contains all sections i created and the reference to the RadRichTextBox is not null. Is there any particular settings i have to do in order to make it printing??

    Thanks,
    Dinesh
  2. Answer
    Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 21 May 2012 Link to this post

    Hello Dinesh,

    The RadRichTextBox has to be added to the visual tree, so that you can print. Check the online demo and its code to see how the example is implemented. If your problem persists, you can send us the created document or the code you generate the document with. A demo project illustrating the issue will, however, be best.

    Kind regards,
    Martin
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Dinesh
    Dinesh avatar
    3 posts
    Member since:
    May 2012

    Posted 23 May 2012 Link to this post

    Hi Martin,

    Now It's working for me with the below code. Thanks for your response.

    RichTextBox.Dispatcher.BeginInvoke((

     

    Action)(() =>

     

    {

    RichTextBox.Document.Measure(

     

    RadDocument.MAX_DOCUMENT_SIZE);

     

    RichTextBox.Document = CreateDocument(grid);

    }));

     

     

    PrintSettings ps = new PrintSettings();

     

    ps.PrintScaling =

     

    PrintScaling.ShrinkToPageSize;

     

    ps.DocumentName =

     

    "MyDocument";

     

    ps.PrintMode =

     

    PrintMode.Native;

     

    rtb.PrintStarted +=

     

    new EventHandler(rtb_PrintStarted);

     

    rtb.Print(ps);
    Thanks,
    Dinesh N.

  5. Dinesh
    Dinesh avatar
    3 posts
    Member since:
    May 2012

    Posted 23 May 2012 Link to this post

    Hi Martin,

    But I am having another issue, Not able to print row details i.e hierarchial Grid data. Please suggest me on this issue, if possible provide sample application printing hierarchial Grid Data.

    Thanks,
    Dinesh N.
  6. Boby
    Admin
    Boby avatar
    595 posts

    Posted 28 May 2012 Link to this post

    Hi Dinesh,
    Unfortunately we don't have such demo application. If you are using the code from RadGridView's demo, you should modify the PrintAndExportWithRadDocumentModel.CreateDocument method, where an instance of RadDocument is created, adding additional document elements. You can examine the possible document elements and their relationships in this help article.

    Regards,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner