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

Insert numbered list programmatically

2 Answers 153 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 21 Mar 2013, 02:27 PM
How can a numbered (or bulleted) list be inserted into a rich text box programmatically?

2 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 26 Mar 2013, 01:21 PM
Hello Igor,

You can do this by using the RadRichTextBox API for text search and selection. Please consider the following code snippet:
radRichTextBox1.Document.Selection.Clear();
DocumentTextSearch search = new DocumentTextSearch(radRichTextBox1.Document);
TextRange range = search.Find("start");
TextRange range2 = search.Find("end", range.EndPosition);
if (range != null && range2 != null)
{
    this.radRichTextBox1.Document.Selection.AddSelectionStart(range.StartPosition);
    this.radRichTextBox1.Document.Selection.AddSelectionEnd(range2.EndPosition);
    this.radRichTextBox1.ChangeListStyle(DefaultListStyles.Bulleted);
}

I hope it helps.
 
All the best,
Jack
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
Igor
Top achievements
Rank 1
answered on 29 Mar 2013, 10:29 AM
Thank you for your help. I managed to achieve this in the following way (VB.NET):

For Each item As String In itemList
    radRichTextBox1.Insert(item & Environment.NewLine)
Next
 
'Format the item list as numbered list
radRichTextBox1.Document.Selection.Clear()
Dim search As New DocumentTextSearch(radRichTextBox1.Document)
Dim range1 As TextRange = search.Find(itemList(0))
Dim range2 As TextRange = search.Find(itemList(itemList.Count - 1), range1.EndPosition)
If range1 IsNot Nothing And range2 IsNot Nothing Then
    radRichTextBox1.Document.Selection.AddSelectionStart(range1.StartPosition)
    radRichTextBox1.Document.Selection.AddSelectionEnd(range2.EndPosition)
    radRichTextBox1.ChangeListStyle(DefaultListStyles.Numbered)
End If
radRichTextBox1.Document.Selection.Clear()
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Igor
Top achievements
Rank 1
Answers by
Jack
Telerik team
Igor
Top achievements
Rank 1
Share this question
or