Insert a Bulleted List in RadRichTextBox

3 posts, 0 answers
  1. Manish Mishra
    Manish Mishra avatar
    11 posts
    Member since:
    Feb 2010

    Posted 06 Apr 2013 Link to this post

    all i want is to insert a simple Bulleted List inside RadRichtextBox.
    Or basically, I want to show few texts in bullets. 
    How do I do that?

    BulletedList list = new BulletedList(this.radRichTextBox1.Document);
    foreach (string item in TableOfContent)
    {
             Paragraph p = new Paragraph();
             p.Inlines.Add(new Span(item));
             list.AddParagraph(p);
             ListItemInfo li = new ListItemInfo(list, p, 1);
    }

    I tried above code and also this.
    Nothing works, not even my text appears inside the richtextbox upon run.
    Please help. 
  2. Justin
    Justin avatar
    35 posts
    Member since:
    Apr 2008

    Posted 20 Nov 2013 Link to this post

    Manish, I do not know if you have been able to resolve this issue or not, but as I am having a similar problem I wanted to add on.  In my case I have been able to format my desired text into bulleted list items - however, I cannot seem to get them to appear WHERE I want them to be.  Using richTextBox.Insert will put the inserted text to the beginning of the document (or rather, after other inserted items prior).


    In my case, what I need is to have the items inserted into the current section of the document that I am working in - which I am not able to do so far.

    Either way - here is the code that I used to insert the bulleted list:



    public void AddSummarySection()
            {
                Section section = new Section();
     
                Paragraph titleParagraph = new Paragraph();
                Span titleSpan = new Span();
                titleSpan.Text = "Current Status Highlights / Executive Summary" + Environment.NewLine;
                titleParagraph.Inlines.Add(titleSpan);
                 
                Span span2 = new Span();
                Span span3 = new Span();
     
                span2.Text = "Wins and Updates:" + Environment.NewLine;
                span3.Text = "Issues and Risks:" + Environment.NewLine;
                //titleParagraph.Inlines.Add(span2);
                //titleParagraph.Inlines.Add(span3);
     
                section.Blocks.Add(titleParagraph);
                this.rtbDocument.Document.Sections.Add(section);
     
                rtbDocument.Document.Selection.Clear();
                rtbDocument.Insert(span2.Text);
                rtbDocument.Insert(span3.Text);
     
                DocumentTextSearch search = new DocumentTextSearch(rtbDocument.Document);
                TextRange range = search.Find(span2.Text);
                TextRange range2 = search.Find(span3.Text);
     
                if (range != null && range2 != null)
                {
                    this.rtbDocument.Document.Selection.AddSelectionStart(range.StartPosition);
                    this.rtbDocument.Document.Selection.AddSelectionEnd(range2.EndPosition);
                    this.rtbDocument.ChangeListStyle(DefaultListStyles.Bulleted);
                }
    }


  3. UI for WinForms is Visual Studio 2017 Ready
  4. George
    Admin
    George avatar
    500 posts

    Posted 25 Nov 2013 Link to this post

    Hello Justin,

    Thank you for contacting Telerik Support.

    In order to insert a bulleted list you will need to use the DocumentList class which is usually used for such listings. A sample method which can be used follows:
    private void AddBulletList(Section sectionToUse = null)
    {
        DocumentList list = new DocumentList(DefaultListStyles.Bulleted, this.richTextBox.Document);
        Section section = sectionToUse ?? new Section();
     
        for (int i = 0; i < 3; i++)
        {
            Paragraph listItemParagraph = new Paragraph();
            Span listItemSpan = new Span("Bullet " + (i + 1));
            listItemParagraph.Inlines.Add(listItemSpan);
            list.AddParagraph(listItemParagraph);
            section.Blocks.Add(listItemParagraph);
        }
     
        if (sectionToUse == null)
        {
            this.richTextBox.Document.Sections.Add(section);
        }
    }

    This method suggests that either a section will be passed or if not a new one will be created. If you want to use it with the current Section you can use the following approach:
    this.AddBulletList(this.richTextBox.Document.CaretPosition.GetCurrentSectionBox().AssociatedSection);

    I hope you will find this helpful.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top