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

Insert a Bulleted List in RadRichTextBox

2 Answers 441 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Manish Mishra
Top achievements
Rank 1
Manish Mishra asked on 06 Apr 2013, 07:24 PM
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 Answers, 1 is accepted

Sort by
0
Justin
Top achievements
Rank 1
answered on 20 Nov 2013, 09:00 PM

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);
            }
}


0
George
Telerik team
answered on 25 Nov 2013, 03:55 PM
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 >>
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Manish Mishra
Top achievements
Rank 1
Answers by
Justin
Top achievements
Rank 1
George
Telerik team
Share this question
or