Add text from SqlDataReader

12 posts, 0 answers
  1. Stas
    Stas avatar
    13 posts
    Member since:
    Feb 2015

    Posted 23 Feb 2015 Link to this post

    Hello! I try to add text to RadRichTextBox but anything it is impossible!
    On standard richtextbox everything is good. How here to make analog of code for RadRichTextBox? Thanks!
    using (SqlDataReader dr = cmd.ExecuteReader())
                  {
                      while (dr.Read())
                      richTextBox1.AppendText("\n" + dr["data"] + ": " + dr["UserName"] + ": " + dr["message"].ToString());
                  }
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 23 Feb 2015 Link to this post

    Hello Stas,

    Thank you for writing.

    Please refer to the following article which explains how you can import data in RadRichTextEditor: Import/Export | UI for WinForms Documentation.

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stas
    Stas avatar
    13 posts
    Member since:
    Feb 2015

    Posted 23 Feb 2015 in reply to Stefan Link to this post

    No, I don't want import or export. I want to learn as to add the text in RadRichTextBox? How to add the text as on a screenshot in the attachment?
    I already tried, it is impossible to me... In standard RichTextBox everything ok
  5. Stas
    Stas avatar
    13 posts
    Member since:
    Feb 2015

    Posted 23 Feb 2015 Link to this post

    Forgive, my question about RadRichTextBox but not radRichTextEditor.
    Please, give a code sample on my question
  6. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 25 Feb 2015 Link to this post

    Hi,

    Adding text in RadRichTextBox and RadRichTextEditor is done via importing, not with the Text property. Here is how your code will look like:
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
     
        string text = "";
     
        using (SqlDataReader dr = cmd.ExecuteReader())
        {
            while (dr.Read())
                text += "\n" + dr["data"] + ": " + dr["UserName"] + ": " + dr["message"].ToString();
        }
     
        radRichTextEditor1.Document = ImportString(text);
    }
     
    public RadDocument ImportXaml(string content)
    {
        TxtFormatProvider provider = new TxtFormatProvider();
        return provider.Import(content);
    }

    Still, we do have a feature request for adding plain text or html text with the Text property. You can track its status and add your vote (like) for it here: http://feedback.telerik.com/Project/154/Feedback/Details/111956-add-radrichtextbox-init-the-content-using-text-property-with-support-of-html-f.

    As to using RadRichTextBox instead of RadRichTextEditor, I would strongly recommend using the latter, as it it a much better version of the editor control.

    I hope that you find this information useful.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Stas
    Stas avatar
    13 posts
    Member since:
    Feb 2015

    Posted 05 Mar 2015 in reply to Stefan Link to this post

    Thanks Bro! I love you!
  8. Stas
    Stas avatar
    13 posts
    Member since:
    Feb 2015

    Posted 05 Mar 2015 Link to this post

    How to add text to an already existing? Analogue of appendtext? That would not load constantly new document...
  9. Stas
    Stas avatar
    13 posts
    Member since:
    Feb 2015

    Posted 05 Mar 2015 Link to this post

    I'm sorry, did using .insert! Thanks!
  10. Stas
    Stas avatar
    13 posts
    Member since:
    Feb 2015

    Posted 05 Mar 2015 in reply to Stas Link to this post

    Oh, no! It does not work ...
    radRichTextBox1.Document.Insert("dfdf", new StyleDefinition());

    Text added without style html....look in attach .
    And I need to be added text to html...
  11. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 06 Mar 2015 Link to this post

    Hello Stas,

    Here you are:
    this.radRichTextEditor1.Document.CaretPosition.MoveToLastPositionInDocument();
    this.radRichTextEditor1.Insert("alabala");

    I hope this helps.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  12. Stas
    Stas avatar
    13 posts
    Member since:
    Feb 2015

    Posted 06 Mar 2015 in reply to Stefan Link to this post

    Thanks bro, but you code inserts text without ntml, see screenshot
  13. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 Mar 2015 Link to this post

    Hello Stas,

    I am working with the latest version of RadRichTextEditor and the behavior is not as you described on my end. 

    Importing file:
    <!DOCTYPE html>
    <html>
    <body>
     
    <span style="color:red"><strong>Здравствуйте!</strong></span>
     
    </body>
    </html>

    results in:
    …......
    <body><p class="NormalWeb "><span class="s_A9BC7DFB">Здравствуйте!TEST</span></p></body></html>

    Attached you can find the sample I am testing with. Can you please have a look at it and let me know how it differs from your setup?

    I am looking forward to your reply.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready