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

RichTextBox with bulleting option

1 Answer 105 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Abisek
Top achievements
Rank 1
Abisek asked on 25 May 2011, 03:27 PM
Needed help in a Rich text box with bulleting option.
 
To achieve this  my code is 
 
<StackPanel Grid.Row="0" Orientation="Horizontal" x:Name="Stack">           
<telerikRibbonBar:RadButtonGroup>               
<telerikRibbonBar:RadRibbonToggleButton x:Name="Bullet" Click="Bullet_Click" Content="."/>            </telerikRibbonBar:RadButtonGroup> 
 </StackPanel>               
<telerik:RadRichTextBox x:Name="RTB" Height="300" Grid.Row="1" Width="600"/>
 
And in class file
 
private void Bullet_Click(object sender, RoutedEventArgs e)
        {
            RadDocument document = new RadDocument();
            document = RTB.Document.Selection.CreateDocumentFromSelection();
            RTB.Document.Selection.AnchorSelectionPositions();
            document = CreateDocumentWithMultiLevelList(document);
            RTB.Document = document;
        }
 
And
 
 
private RadDocument CreateDocumentWithMultiLevelList(RadDocument document)
        {
            Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
 
            BulletedList bulletList = new BulletedList(document);
            bulletList.Style = DefaultListStyles.Numbered;
            foreach (Paragraph paragraph in document.EnumerateChildrenOfType<Paragraph>())
            {
                bulletList.AddParagraph(paragraph);
            }
           
            document.Sections.Add(section);
            return document;
        }
 
 
The problem is that my code is replacing not only the selected text but the entire content of the Rich text block with my formatted text. Can I replace only the selected content by my new bulleted content?

1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 30 May 2011, 05:19 PM
Hi Abisek,

The part of the document that is not selected is stripped, because you change the Document of RadRichTextBox to the newly created one.
If you want to add bullets to all selected paragraphs, you can invoke the following method, which operates on the selection:

RTB.ChangeListType(ListType.Bulleted);
You don't need to have any pre- or post-processing, anchoring the selection positions, etc.

I hope this helps.

Best wishes,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Abisek
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or