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

how to dynamically load RadRichtextbox,raddocument and those property

24 Answers 1047 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
vijayan
Top achievements
Rank 1
vijayan asked on 01 Dec 2010, 06:46 AM
Hi,
    i have doubt on radrichtextbox and those property. am trying to do from radrichtextbox export to PDF files with image also. but i couldnot access all property in viewmodel class.can you tell me how to access and how to dynamic load all control in view model?

Example

    view model class am writing one method. in this method am trying to add paragraph,section and ect.. but it is not working.

 

 

RadDocument rad = new RadDocument();

 

 

 

RadRichTextBox richtextbox=new RadRichTextBox();

 

richtextbox.Document.Section =

 

"10,10,10,10";

 

 

 

Button button = new Button();

 

button.Content =

 

"Click Me";

 

button.Click += OnButtonClick;

 

 

richtextbox.ChildrenOfType.Add(textBox);

 

24 Answers, 1 is accepted

Sort by
0
Accepted
Iva Toteva
Telerik team
answered on 03 Dec 2010, 05:36 PM
Hello vijayan,

Please find attached a demo, illustrating how you can create a document in code-behind. It also shows how you can export the document to PDF.
The InlineUIContainers, however, are not exported and the button, which you can see and click if you load the document in RadRichTextBox, will not be exported.
There should be no problem for you to implement that in your ViewModel class.
Let us know if you need further assistance.

All the best,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
vijayan
Top achievements
Rank 1
answered on 04 Dec 2010, 08:11 PM
Hi Iva,
    Thanks for giving good solution. how do i add image with out UIContainer. as you told that if we add UIContainer using image we cannot export data to PDF.then is there any other solution to export PDF? .i have to align some data using radrichtextbox or rad document.totally  i need  4 cells(Column) and  many rows.those value dynamically i have to take all data from my database table. example left hand side  image.. is there any solution. please help me.. i could not find solution.finally i have export all data to PDF same format(design). Thanks in Advance.
Here below  i mention example of my report.

Report Title with Logo

LastName  :  Vijayan
FirstName : John
_________________________                                                            Here I want Image.10 * 10 size.

Age : 25

___________

Biography

some textsome textsome textsome textsome textsome text
some textsome textsome textsome textsome textsome text
some textsome textsome textsome textsome textsome text
0
Accepted
Iva Toteva
Telerik team
answered on 06 Dec 2010, 05:42 PM
Hi vijayan,

If you use ImageInline, the picture will also be exported using the format provider. I have modified the previous demo to include a picture. The picture is included in the project, but it can be taken from a database, as long as you can provide a Stream that contains it.
Note, that as of now we only support inline images, that is you cannot make the text flow on the sides of the picture. However you can use tables to achieve your scenario.

All the best,

Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
vijayan
Top achievements
Rank 1
answered on 07 Dec 2010, 07:14 AM
Hi Iva,

    Thanks for your quick response..
0
vijayan
Top achievements
Rank 1
answered on 07 Dec 2010, 04:25 PM
Hi Iva,
    Sorry for disturbing again. i was created MSWord docx and i created a print template doc. example am i given below. first load all xml data to one collection then am importing all data to word to raddocument. then in this document am finding like this "<text>". then i have replaced to orinigal value. but i could not replace raddocument? ca u tell me how to do this situation? thanks in advance.
This sample of ms word content.

Player Card Profile

Profile

 

First Name

<FirstName>  <LastName>  <MIName>

Status

<status>

 

i have replace of <FirstName> like.

am writing one method like this.

 

 

private string GetActualValue(string originalValue, List<player> Players)

 

{

 

 

string myResult = originalValue;

 

 

 

if (originalValue.Substring(0, 1) == "<" && originalValue.Substring(originalValue.Length - 1, 1) == ">")

 

{

 

 

var result = from myPlayers in Players

 

 

 

where myPlayers.Title.Equals (originalValue.Substring (1,originalValue.Length-2))

 

 

 

select myPlayers;

 

 

 

if (result.ToList ().Count > 0 )

 

{

 

 

player myPlayer = (player)result.ToList()[0];

 

myResult = myPlayer.Name.ToString();

}

}

 

 

return myResult;

 

}



public

 

 

RadDocument ImportWordDoc()

 

{

LoadXML();

 

 

 

using (Stream stream = Application.GetResourceStream(GetResourceUri("NEW.docx")).Stream)

 

{

Document.LayoutMode =

 

DocumentLayoutMode.Flow;

 

Document =

 

new DocxFormatProvider().Import(stream);

 

}

 

 

foreach (Inline varInline in Document.EnumerateChildrenOfType<Inline>())

 

{

 

 

if (varInline.GetType().ToString().Equals("Telerik.Windows.Documents.Model.Span"))

 

{

((

 

Span)varInline).Text = GetActualValue(((Span)varInline).Text, Players);

 

 

 

//Span mySpan = new Span(GetActualValue(((Span)varInline).Text, Players));

 

 

 

// Document.Children.AddAfter(varInline, mySpan);

 

 

 

//bool isRemoved = Document.Children.Remove(varInline);

 

}

}

 

 

Document;

 

}

0
Iva Toteva
Telerik team
answered on 09 Dec 2010, 12:18 PM
Hi vijayan,

You can replace the document just by invoking:

this.radRichTextBox.Document = Document;

However, it seems to me that your scenario is practically mail merge. This feature is on our to-do list for next year, but what you can do currently is to use the newly introduced Find functionality as shown in the demo in this forum thread.
Basically, you perform a search for a string and then, you can do as you please with the results. The method in the demo selects all occurrences of the word.
private void buttonFind_Click(object sender, RoutedEventArgs e)
{
    this.radRichTextBox.Document.Selection.Clear();
 
    DocumentTextSearch search = new DocumentTextSearch(this.radRichTextBox.Document);
    foreach (var textRange in search.FindAll(this.textBox.Text))
    {
        this.radRichTextBox.Document.Selection.AddSelectionStart(textRange.StartPosition);
        this.radRichTextBox.Document.Selection.AddSelectionEnd(textRange.EndPosition);
    }          
}

If you add
this.radRichTextBox.Insert(sometext);
 after setting the selection end, the text will be replaced.

Kind regards,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
vijayan
Top achievements
Rank 1
answered on 09 Dec 2010, 01:21 PM
Hi Iva,
    Thanks. is there any possiblities connecting with out WCF using telerik report?. we are using MAC OS . it is not support WCF on mac machine. is there any other solution?. thanks in advance.

Thanks
Vijayan
0
Vassil Petev
Telerik team
answered on 09 Dec 2010, 02:36 PM
Hi vijayan,

Please, ask Telerik Reporting questions in the Telerik Reporting Forum. I am sure the Reporting guys will help you out. Just describe your problem in detail, i.e. what services you use, what technology (SL, WPF, etc) and what the exact problem is and they will help.


Kind regards,
Vassil
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
vijayan
Top achievements
Rank 1
answered on 21 Dec 2010, 07:24 AM
Hi,
I am using telerik radrichtextbox in that rad document. rad document is readonly mode and spellcheck=false.

 

 

 

am dynamically attaching all the content and sections to rad document. i can see my result. but while am drag or selecting inside rad document that time application crashed. but am using readonly mode. i dont know why happening like this.here i mention below sample code .

 

<

 

 

telerik:RadRichTextBox x:Name="print" IsReadOnly="True" IsSpellCheckingEnabled="False" />

 

 

 

 

 

<telerikControls:RadButton x:Name="ExportPDF" Content="ExportPDF" Width="80" Height="30" Click="ExportPDF_Click" VerticalAlignment="Bottom">

 

 

 

 

 

 

 

 

 

</telerikControls:RadButton>

 

one more doubt. am using rad button. i need to show in this button bottom of document.how can i find how many rad document and how can i set radbutton bottom ? am doing dynamically so i dont know how many rad document will come.
Thanks in Advance

0
Iva Toteva
Telerik team
answered on 23 Dec 2010, 11:12 AM
Hi vijayan,

What exception are you getting? If you open a support ticket and send over a sample project, we may be able to help you further.
Just to be on the safe side, you can view only one RadDocument in a RadRichTextBox. The sample project involved only one RadRichTextBox and one RadDocument. No matter how many sections, paragraphs, spans, etc. you add, the controls that come after the rich text box will appear properly.

If you, however, have more than one RadDocuments which you want to show in different RadRichTextBox-es, you would have to implement some custom logic of yours. One approach would be to put RadRichTextBox in a DataTemplate for some ItemsControl, e.g. a ListBox, and then set the DataContext and ItemsSource of the ListBox, as shown in the demo in this forum thread (the post from October 6th). 
Another option would be to add them to the logical tree of some control, which is already created like this:

foreach(RadDocument doc in documents)
{
   RadRichTextBox rrtb = new RadRichTextBox();
   rrtb.Document = doc;
   layoutRoot.Children.Add(rrtb);
}
Let us know if that doesn't answer your question.

All the best,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
vijayan
Top achievements
Rank 1
answered on 08 Feb 2011, 11:28 AM

Hi,
How to set the MaxLength property of the input area of the combobox? i had tried in this following example
http://www.telerik.com/help/silverlight/radcombobox-howto-set-max-length-input-area.html

i created class name as "EditableRadCombo" one project files. after that i access in this project  in my Xaml page like this..
Create namespace for that project  

 

xmlns

 

 

:Editable="clr-namespace:eAnalyze.Common"

after that am calling

 

 

 

 

<telerik:RadComboBox x:Name="EventType" Grid.Row="3" Grid.Column="1" Width="345" Height="22" SelectedIndex="0" Text="{Binding EventType}" VerticalAlignment="Center"

 

 

 

SelectedValue="{Binding EventType,Mode=TwoWay}" DisplayMemberPath="EventTypeName" SelectedValuePath="EventTypeID" IsTextSearchEnabled="False"

 

 

 

IsEditable="True" TabIndex="4" LostFocus="EventTypeLostFocus" SelectionChanged="EventType_SelectionChanged" Editable:EditableComboxMaxlengthProperty.MaxLength="10">

 

 

 

 

 

 

 

 

</telerik:RadComboBox>

if i build application got one error.
that is No maxlegth property avaiable.

Thanks
Vijayan P

 

0
Yana
Telerik team
answered on 14 Feb 2011, 12:04 PM
Hi vijayan,

The property should be set like this:

<telerik:RadComboBox  IsEditable="True" Editable:EditableRadCombo.MaxLength="10" ...>

I've attached a simple example to demonstrate the approach.

Greetings,
Yana
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Matt
Top achievements
Rank 1
answered on 11 Mar 2011, 11:51 AM
Hi,
I have opened a docx document in RadRichtextbox and looking for a way to add another document on top of this current document.
Is there a way to dynamically append one document to another opened document. Both documents are docx type. 

Thanks
0
Boby
Telerik team
answered on 17 Mar 2011, 09:56 AM
Hi Matt,

We are sorry for the delay, but we were busy with the new Q1 release.
You can add second document in the beginning of the existing document by creating document fragment, as follows:

private void buttonLoadSecondDocument_Click(object sender, RoutedEventArgs e)
{
    OpenFileDialog openFileDialog = new OpenFileDialog();
    if (openFileDialog.ShowDialog() == true)
    {
        using (Stream stream = openFileDialog.File.OpenRead())
        {
            RadDocument document2 = new DocxFormatProvider().Import(stream);
            document2.Selection.SelectAll();
 
            this.radRichTextBox.Document.InsertFragment(document2.Selection.CopySelectedDocumentElements());
        }
    }
}
InsertFragment has another overload that accepts DocumentPosition, so you can insert the second document anywhere in the first one.

Don't hesitate to contact us if you have other questions.

Greetings,
Boby
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Matt
Top achievements
Rank 1
answered on 31 Mar 2011, 11:54 AM
I am using Q1 2011 release and getting an exception "Specified function is not supported" on line
RadDocument docment = new PdfFormatProvider().Import(stream);

On Telerik demo site of RadRichTextEditor it is stated "Support for import/export in .docx, .html, .pdf, .xaml and .txt formats".
I am trying to import pdf document.

Thanks,


0
vijayan
Top achievements
Rank 1
answered on 31 Mar 2011, 03:05 PM
Hi matt,

     hey you have to add this two dll.

using

 

 

Telerik.Windows.Documents.FormatProviders.OpenXml.Docx;

 

using

 

 

Telerik.Windows.Documents.FormatProviders.Pdf;

this is method return document which contain imported docx .. just you pass local path of ms word file then it will return.
private RadDocument GetAllElementFromWord(string localPath)

 

 

{

 

RadDocument CommonDocument =

 

new RadDocument();

 

 

 

 

 

using (Stream stream = Application.GetResourceStream(GetResourceUri(localPath)).Stream)

 

 

{

 

CommonDocument.LayoutMode = DocumentLayoutMode.Flow;

 

CommonDocument =

 

 

new DocxFormatProvider().Import(stream);

 

 

}

 

 

 

 

return CommonDocument;

 

 

}

this method check whether correct word document file or not and return resource file. before run application make sure whether that ms word file is resource or not. if you want resource file right click ms word file property make resource file..

 

 

private

 

 

 

Uri GetResourceUri(string resource)

 

 

{

 

 

 

 

AssemblyName assemblyName = new AssemblyName(this.GetType().Assembly.FullName);

 

 

 

 

 

string resourcePath = "/" + assemblyName.Name + ";component/" + resource;

 

 

Uri resourceUri =

 

 

new Uri(resourcePath, UriKind.Relative);

 

 

 

 

 

return resourceUri;

 

 

}

if you have doubt on this please let me know . my mail id is vijayan.perumalsamy@marlabs.com.

Thanks
Vijayan

0
Iva Toteva
Telerik team
answered on 31 Mar 2011, 05:42 PM
Hello Vijayan,

Thank you for taking part in this discussion. However, I think that Matt has something else in mind.
@Matt: PDF import is currently not supported. This is indeed not very clear in the article about data providers where the focus is on data binding. However, the fact that only PDF export is available is specifically accented in this article about import and export. We will make sure to update the other article, so that no more misunderstandings occur.
PDF import is on our to-do list, but has not been scheduled yet and will not be implemented for Q2.

All the best,
Iva
the Telerik team
0
udaybhaskar
Top achievements
Rank 1
answered on 28 Jul 2011, 12:40 PM
Hi Iva,

I have an issue in the attached code snippet insertcustomcontrol.zip. What I want is I want to do the load and export functionality without UI. I mean with out actual control is created I have to achieve the functionality.
So I have commented the below code
MainPage.XAML file

 

 

 

<!--<telerik:RadRichTextBox Name="editor" Grid.Row="1" >

 

<telerik:RadRichTextBox.Document>

<telerik:RadDocument LayoutMode="Paged" />

</telerik:RadRichTextBox.Document>

</telerik:RadRichTextBox>-->

and declared the control like below..

 

 

 

public partial class MainPage : UserControl

 

 

 

 

{

 

 

 

private RadRichTextBox editor;

 

 

 

private RadDocument document;
...
and modified the event as below...

 

 

 

private void buttonLoadDocumentInEditor_Click(object sender, RoutedEventArgs e)

 

{

editor =

 

new RadRichTextBox();

 

 

 

this.editor.Document = document;

 

}

so...when I build the code it is fine..but I am getting runtime exception when trying to export the doc to "docx" format. I am not having PDF related Dlls as I am using a 2010 version of Telerik.
attached the Error Screen Shot.

Please let me know where the issue is???

0
Ivailo Karamanolev
Telerik team
answered on 02 Aug 2011, 04:20 PM
Hi Udaybhaskar,

We generally do not have a practice to support old versions except in cases where the issue is well known and there is an easy workaround for it. In your case, it seems that either the document is invalid or there is a bug in the DocxFormatProvider. We advise you to try importing and exporting the document with the latest version (2011 Q2 - 2011.2 712) and see if the problems persist. If so, we'll be glad to investigate further and fix any issues present.

Regards,
Ivailo
the Telerik team

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

0
Nagarjun
Top achievements
Rank 1
answered on 08 Nov 2011, 08:08 AM
hi ivailo,

                When am going to import the document from docx file to radrichtextbox it is giving exception, that line of code is

this

 

 

.RTBox.Document = new DocxFormatProvider().Import(stream);

 


and error is

Could not load type 'Telerik.Windows.Documents.Packaging.ZipPackage' from assembly 'Telerik.Windows.Documents, Version=2011.3.1020.1040, Culture=neutral, PublicKeyToken=5803cfa389c90ce7'.

can you please help me!

Thanks & Regards,
Nagarjun
0
Iva Toteva
Telerik team
answered on 08 Nov 2011, 04:33 PM
Hi Nagarjun,

In order to use DocxFormatProvider, you also need to reference the Telerik.Windows.Zip dll, which can be found in the same folder where you have installed or extracted the zip with the other assemblies. You can find a list of all required assembly references here.
Note that you must reference the same version of all assemblies and cannot have different versions of Telerik.Windows.Documents and Telerik.Windows.Documents.FormatProviders.OpenXml for example.

All the best,
Iva Toteva
the Telerik team

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

0
Jeff
Top achievements
Rank 1
answered on 21 Mar 2014, 08:08 AM
This was asked and answered over 3 YEARS AGO. Why is it still not in the documentation?

It took me over three hours to find this post. Thanks again for the colossal waste of my time.
0
Petya
Telerik team
answered on 21 Mar 2014, 12:15 PM
Hello Jeff,

Could you please share what information exactly you had troubles finding in the documentation? This forum thread is rather long and multiple topics have been discussed in it. We will make sure to point you to the appropriate resources or in case such are missing, create them.

Thank you for your feedback in advance!

Regards,
Petya
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Jeff
Top achievements
Rank 1
answered on 21 Mar 2014, 09:54 PM
I am in the wrong forum. I don't know if my post applies to Silverlight or not, I am using WinForms. I was led here by a Google search for WinForms RTB, because Telerik Forum Search is horrible. I asked support to delete my post for this reason, but they did not.

I was replying to a post from Boby on March 17 2011 and was referring to the SelectAll() method being used to retrieve a Fragment. There is no documentation in WinForms about how to get a DocumentFragment from the Document.

I ended up using the standard Microsoft RichTextBox anyways; it works better, has better documentation and is easier to use.
Tags
RichTextBox
Asked by
vijayan
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
vijayan
Top achievements
Rank 1
Vassil Petev
Telerik team
Yana
Telerik team
Matt
Top achievements
Rank 1
Boby
Telerik team
udaybhaskar
Top achievements
Rank 1
Ivailo Karamanolev
Telerik team
Nagarjun
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Petya
Telerik team
Share this question
or