SfRichTextBoxAdv - Get the Inline/SpanAdv of the selection

Is there a way to get the Inline or SpanAdv object of the selected text in a SfRichTextBoxAdv ?

I would like to let the user select text and press a button, when pressed i want to add the selected inline to a collection.
Later on i want to change the text in these inlines by casting them to a SpanAdv and setting their Text property.

1 Reply

VM Venkatesan Mani Syncfusion Team December 26, 2017 12:49 PM UTC

Hi Jimmi,

Thank you for contacting Syncfusion support.

Our SfRichTextBoxAdv control supports API to insert/modify the text at current selection by using ‘InsertText’ method of ‘SelectionAdv’ class. As we mentioned in the forum #135190, you can preserve the ‘TextPosition’ at selection using hierarchical index and convert it back as ‘TextPosition’ using ‘GetTextPosition’ API of ‘DocumentAdv’. Then you can update the selection with the retrieved ‘TextPosition’ instances and then modify the text using above mentioned ‘InsertText’ API.

API reference links:
GetTextPosition: 
https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.RichTextBoxAdv.DocumentAdv.html#Syncfusion_Windows_Controls_RichTextBoxAdv_DocumentAdv_GetTextPosition_System_String_ 

Select API:
https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.RichTextBoxAdv.SelectionAdv.html#Syncfusion_Windows_Controls_RichTextBoxAdv_SelectionAdv_Select_Syncfusion_Windows_Controls_RichTextBoxAdv_TextPosition_Syncfusion_Windows_Controls_RichTextBoxAdv_TextPosition_ 

InsertText API:
https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.RichTextBoxAdv.SelectionAdv.html#Syncfusion_Windows_Controls_RichTextBoxAdv_SelectionAdv_InsertText_System_String_ 

We have also prepared an simple sample to demonstrate the same. please find the sample from the following link,
 

Sample link:
Sample.zip

Please let us know if this satisfies your requirement. If any further customization is required kindly revert us. 

Regards,
Venkatesan M.
 


Loader.
Up arrow icon