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

dialogs must be user-initiated

11 Answers 99 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 04 Apr 2012, 11:46 AM
I have just upgraded to the latest build (not the IB)
And i started getting an error while trying to print.

Here is my code, which i have pretty much taken from the sample:

private bool CanPrint(object param)
        {
            return true;
        }
 
        private void Print(object param)
        {
            RadGridView grid = (RadGridView)param;
            RadRichTextBox rtb = new RadRichTextBox() { Height = 0 };
 
            rtb.Name = "RadRichTextBox1";
 
            Grid parent = grid.ParentOfType<Grid>();
            if (parent != null && parent.FindName(rtb.Name) == null)
            {
                parent.Children.Add(rtb);
                rtb.ApplyTemplate();
            }
 
            rtb.Dispatcher.BeginInvoke((Action)(() =>
            {
                rtb.Document = CreateDocument(grid);
            }));
 
            rtb.Print("MyDocument", Telerik.Windows.Documents.UI.PrintMode.Native);
        }
 
        private RadDocument CreateDocument(RadGridView grid)
        {
            List<GridViewBoundColumnBase> columns = (from c in grid.Columns.OfType<GridViewBoundColumnBase>()
                                                     orderby c.DisplayIndex
                                                     select c).ToList();
 
            Telerik.Windows.Documents.Model.Table table = new Telerik.Windows.Documents.Model.Table();
 
            RadDocument document = new RadDocument();
            Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
            section.Blocks.Add(table);
             
            document.Sections.Add(section);
 
            AddDataRows(table, grid.Items, columns, grid);
 
            return document;
 
        }


I did get this error once before when i had a breakpoint in the code before i upgraded from Q3 release.
But now that i am using Q1 2012 release i get this error every time.

My code is in a viewmodel.


11 Answers, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 09 Apr 2012, 09:47 AM
Hello Andrew,

The problem you are seeing resides in the very core of Silverlight. In Silverlight you can perform certain actions only when they are user-initiated (that would mean on a button click for example). Here you are opening a save file dialog when a button is clicked which is correct. But there is one more thing. Silverlight has a timeout limit during which the dialog must be shown. If that doesn't happen, a SecurityException is thrown.
The thing is your grid is too big so the creation of a RadDocument containing all information takes too long and the dialog tries to open too late when this timeout has already been exceeded.
You can create two buttons for example - one to prepare the document and one to print it. We know this is uncomfortable and not so user friendly but unfortunately is the only way to overcome this Silverlight limitation.

Please revise and get back to us with your opinion.

All the best,
Andrew
the Telerik team

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

0
Andrew
Top achievements
Rank 1
answered on 10 Apr 2012, 04:02 AM
Dear Andrew

I tested this theory by removing all the code that builds the table, in fact all the code except the call to print the document. 
In this case an empty document. The error still occurs. It happens virtually instantaneously after i press the button.

My new code:
RadRichTextBox rtb = new RadRichTextBox() { Height = 0 };
 
rtb.Name = "RadRichTextBox1";
rtb.Document = new RadDocument();
rtb.Print("MyDocument", Telerik.Windows.Documents.UI.PrintMode.Native);


I am afraid that your theory does not appear to apply here. There must be another reason for this error.
0
Andrew
Telerik team
answered on 11 Apr 2012, 11:33 AM
Hello Andrew,

I checked your account to see what version you previously worked with. It turns out we have added a lot of features since then and that has slowed down the initialization of RadRichTextBox.

As a workaround we would suggest initializing and adding the RadRichTextBox to the visual tree somewhere else (in the constructor of the page for example) and only setting the Document in the button click event handler. However, it is possible that this approach also results in the same exception, if the document is too big and its creation and layout require more time than the limit of the print dialog.

Kind regards,
Andrew
the Telerik team

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

0
Andrew
Top achievements
Rank 1
answered on 19 Apr 2012, 03:59 AM
So in other words there is no way to guaranty that the printing will not cause an exception? 
0
Andrew
Telerik team
answered on 19 Apr 2012, 12:49 PM
Hello Andrew,

The error occurs because you instantiate the RadRichTextBox (which takes quite some time), assign a document (which takes time too) and if the document is big that takes additional time.

In order to ensure that the timeout of the PrintDialog will not be exceeded, you can create a print-preview like window with RadRichTextBox and a Print button in it. When the user decides to print the grid view and clicks a button, build the document and show in in a window with RadRichTextBox. You can have a button in this window which invokes only the print command. In this way, the successful printing of the document would be guaranteed.

I hope you find this solution acceptable.

Kind regards,
Andrew
the Telerik team

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

0
Gitit
Top achievements
Rank 1
answered on 09 Jun 2015, 10:33 AM

Is there any fix to this issue in a later version ?

I'v downloaded the last version, and i get the same error.

(my code was copied from your demos site: http://demos.telerik.com/silverlight/#GridView/PrintAndExportWithRadDocument))

Also didn't succeed to print from the online demo itself.

ANY solution to that ?? 

the only print that worked for me is to use PrintToHtml method that doesn't seem to allow any styling at all.

Thanks,

Gitit

 

0
Tanya
Telerik team
answered on 10 Jun 2015, 04:31 PM
Hi ,

The discussed issue is related to a limitation in the framework and we are not aware of any released fix for it. At this the only workaround of this limitation is the one suggested below by Andrey.

I tested our demos and couldn't reproduce the described behavior - the document is printed as expected. Are you testing with the same data or with another? Could you give us exact steps to reproduce this in order to test on our end and check if there is something else preventing you from printing?

Regards,
Tanya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Gitit
Top achievements
Rank 1
answered on 11 Jun 2015, 08:41 AM

Thank you for your reply.

I'm sorry to hear that there is no fix to this problem.

Meanwhile I'v succeeded to print only grid view with several rows (The grid view contains 20 columns).

I guess I'll have no choise but to implement the suggested solution.

Thanks,

Gitit

0
Gitit
Top achievements
Rank 1
answered on 18 Jun 2015, 10:56 AM

My gridview contains row details that has child gridview. 

How can I print my grid including its row details ?

No matter what I do I wasn't able to print it, only the parent grid.

I'll be glad to hear if you have any solution.

Thanks, 

Gitit

0
Petya
Telerik team
answered on 23 Jun 2015, 08:49 AM
Hello Gitit,

I'd suggest adopting the approach demonstrated in this online example which utilizes RadDocument. You can subscribe to the ElementExporting event of RadGridView when exporting the document, iterate the nested RadGridViews and export them separately. You can also take a look at this demo showing export of RowDetails.

I hope this is useful.

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Gitit
Top achievements
Rank 1
answered on 23 Jun 2015, 09:56 AM
thanks, I'v already did it.
Tags
RichTextBox
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Telerik team
Andrew
Top achievements
Rank 1
Gitit
Top achievements
Rank 1
Tanya
Telerik team
Petya
Telerik team
Share this question
or