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

Null reference exception when Printing

4 Answers 93 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dinesh
Top achievements
Rank 1
Dinesh asked on 16 May 2012, 12:40 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 21 May 2012, 11:56 AM
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 >>

0
Dinesh
Top achievements
Rank 1
answered on 23 May 2012, 11:15 AM
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.

0
Dinesh
Top achievements
Rank 1
answered on 23 May 2012, 11:20 AM
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.
0
Boby
Telerik team
answered on 28 May 2012, 09:40 AM
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 >>

Tags
RichTextBox
Asked by
Dinesh
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Dinesh
Top achievements
Rank 1
Boby
Telerik team
Share this question
or