how to supply input string to the content of the richTextBox and retrieving the edited content

6 posts, 1 answers
  1. Edward Pauley
    Edward Pauley avatar
    48 posts
    Member since:
    May 2010

    Posted 21 Mar 2011 Link to this post

    Hi

    I am not sure whether i am using the correct control or not. Basically, I want to use a control which will let the user realize that they type something wrong and suggest the correct answer. And radrichtextbox is the only control which i knows so far (tried spellCheck and that one doesn't work very nicely during opening multiple radwindow levels).

    basically, i have Customer table which have the fields
       CustomerId, customerName, customerComment (string)
    that customer collection will be bounded to the radgridview . And inside my radgridview will have an unbound column which contain a radbutton. When i click on that button , a pop-up radwindow which contains the RadRichTextBox will appear and let me modify the CustomerComment field

    I read your online document and example and only see that the radrichtextbox will accept a Document type for its content (not a string type). In my case, i only have a string field. 

    ------->
    so what i did is that , i create a Document on the fly . That document will have one paragraph. Inside that paragraph will have a span element . The way i did that is because i ONLY know that the span element will have the TEXT property which will let me set span.Text = customerComment.
    And after user modify the content in the richTextBox, i will search for that span element in the RichTextBox and retrieving that TEXT property in order to update my customerComment.

    I do know that my solution is kind of awkward. But i can't really find a way to use the radrichtextbox in order to let user see my customerComment ----> then modify it (having spellcheck) -----> then update that modified content to my CustomerComment field 

    My Question: can you suggest a proper way to accomplish my task : "having spellcheck during type CustomerComment field" (it is not a Document type it is just a string type)
    Any control is fine. There is no need to radrichtextbox. A normal textbox is fine but it must have spell check (but not forcing the user to click on a button which ask for spellCheck like the one in your demo of SpellChecker). It should spellcheck automatically.

    Note; with my current solution for the RichTextBox. It does take SOME TIME in order to pop-up the comment Radwindow when the button has been clicked. I don't really know why it takes too long (around 6-7 second waiting) to let the window pop-up.

    A snippet of my awkward solution
    //Create Document for RadRichTextBox
               RadDocument document = new RadDocument();
               Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
               Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph();
               //Setting the value of the comment to richTextBox
               Telerik.Windows.Documents.Model.Span span = new Telerik.Windows.Documents.Model.Span() { Text = selectedTBDocumentLine.CustomerComment };
                
               paragraph.Inlines.Add(span);
               
               section.Children.Add(paragraph);
               document.Sections.Clear();
               document.Sections.Add(section);
               /////
               commentScreen.commentRTB.Document = document;
               commentScreen.Closed += new EventHandler<WindowClosedEventArgs>(commentScreen_Closed);
               commentScreen.ShowDialog();
           }
     
           void commentScreen_Closed(object sender, WindowClosedEventArgs e)
           {
               (sender as RadWindow).Closed -= commentScreen_Closed;
               if (commentScreen.Header == "Customer Comment")
               {
                     // update the customerComment through the content of the radrichtextbox
                   selectedTBDocumentLine.CustomerComment = (commentScreen.commentRTB.Document.Sections.First.EnumerateChildrenOfType<Telerik.Windows.Documents.Model.Paragraph>().First().Inlines.First as Telerik.Windows.Documents.Model.Span).Text;
     
                   //selectedTBDocumentLine.CustomerComment = commentScreen.commentTB.Text;
                   autoSave();
     
               }



    thanks
  2. Answer
    Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 23 Mar 2011 Link to this post

    Hello Edward Pauley,

    RadRichTextBox does not have a Text property because different formats for import and export of documents are supported – XAML, HTML, Docx, RTF and plain text. In order to set the contents of the document, it should be clear what format the data is in. For easier extensibility and separation of concerns, format providers that deal with the import and export of the documents are used. Here is a list of the currently available format providers and the assemblies they are included in:

    • TxtFormatProvider (plain text) – Telerik.Windows.Documents;
    • DocxFormatProvider - Telerik.Windows.Documents.FormatProviders.OpenXml;
    • RtfFormatProvider - Telerik.Windows.Documents.FormatProviders.Rtf;
    • HtmlFormatProvider - Telerik.Windows.Documents.FormatProviders.Html;
    • XamlFormatProvider - Telerik.Windows.Documents.FormatProviders.Xaml;
    • PdfFormatProvider - Telerik.Windows.Documents.FormatProviders.Pdf.
    You can read more about the use of format providers here

    Overall, what you need to do to get the content of the document in a specific format is to create an instance of the corresponding provider and export the document. An example is illustrated below:

    public string GetXAML(RadDocument document)
    {
       XamlFormatProvider provider = new XamlFormatProvider();
       return provider.Export(document);
    }

    To get the text stripped of all formatting, you can use TxtFormatProvider, which is included in the Telerik.Windows.Documents assembly.

    Setting the content of RadRichTextBox can be done in a similar manner, if you have the content in one of these formats. For example, importing an HTML string in the document of a RadRichTextBox can be done as follows:

    public void ImportHtml(string content)
    {
       HtmlFormatProvider provider = new HtmlFormatProvider();
         this.radRichTextBox.Document = provider.Import(content);
    }

    There are some methods in the API that can be used for updating the content of the document once it it shown on screen.
    Last but not least, you can data-bind the content of RadRichTextBox using the data providers, built on top of some of the format providers. You might want to review the this article about the use of data providers.
    Last but not least, there is a demo of RadRichTextBox in a RadGridView in this forum thread.

    Regards,
    Author nickname
    the Telerik team
    Iva
    the Telerik team
  3. DevCraft banner
  4. Amruta
    Amruta avatar
    11 posts
    Member since:
    Mar 2015

    Posted 27 Mar 2015 in reply to Iva Toteva Link to this post

    How to retrieve text of RadRichTextBox??
    example : <hrml> <body> Sample Data </body></html>
    Output : Sample data
    How can I get just data/text entered by user and NO HTML tags????
    Thanks.
  5. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 30 Mar 2015 Link to this post

    Hi Amruta,

    You could use the TxtFormatProvider to get the plain text from the RadRichTextBox control. More information and examples about how to use this feature you could find in the Import/Export article in our documentation.

    Hope this helps.

    Regards,
    Tanya
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  6. Amruta
    Amruta avatar
    11 posts
    Member since:
    Mar 2015

    Posted 31 Mar 2015 in reply to Tanya Link to this post

    Thanks Tanya for reply.

    Below Code works if I write it in code behind file :
       ITextBasedDocumentFormatProvider exporter = new TxtFormatProvider();
                
       string text = exporter.Export(this.radtextbox.Document);

    But I need to do validation in model (using MVC pattern),where I can not retrieve RadDocument object ...Can you suggest how to pass RadDocument object to model to do this validation please???

  7. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 02 Apr 2015 Link to this post

    Hello Amruta,

    You could validate the content of a RadDocument using the built-in validation. The validation should be applied over the content in the document and you do not need to pass the RadDocument instance - just pass the extracted content using the TxtFormatProvider. In order to implement your own validation rule you should inherit the ValidationRule abstract class and implement the Validate method, which determines whether the content is valid or not. I am sending you a sample project which demonstrates the validation and returns that the document is valid if its content length is between 5 and 15 symbols.

    Hope this helps.

    Regards,
    Tanya
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
DevCraft banner