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

Selection Text Major Bug

6 Answers 17 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Atif
Top achievements
Rank 1
Atif asked on 11 Aug 2014, 12:24 PM
Radrichtextbox we are facing little problem which i need your help, Might i am missing something or this is internal bug.We area trying to get complete document text with all punctuation etc.Code snippet is give below all code work fine if document does not have any punctuation or quotation, But for instance if there is any word likewise.

Telerik is great,

so the code would discard great, because it has comma code is given below please its a request help me on this issue and give me chance of thanks.

            DocumentPosition position = new DocumentPosition(this.MacroRichTextBox.Document);            do            {                  var id = position.GetCurrentSpanBox();                if (!(id ==null))                {                    string word = position.GetCurrentSpanBox().Text;
                    DocumentPosition wordEndPosition = new DocumentPosition(position);                    wordEndPosition.MoveToCurrentWordEnd();                    this.MacroRichTextBox.Document.Selection.AddSelectionStart(position);                    this.MacroRichTextBox.Document.Selection.AddSelectionEnd(wordEndPosition);                }            } while (position.MoveToNextWordStart()); 

ATIF SHAHZADSoftware Developer 

6 Answers, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 14 Aug 2014, 07:47 AM
Hello Atif,

Thank you for contacting us.

Let me get straight to the question. In order to select the entire content in a document I would suggest you to use the following approach: 

this.radRichTextBox.Document.Selection.SelectAll();
You can also get the selected content like this:

this.radRichTextBox.Document.Selection.GetSelectedText();
 I hope this information is helpful. Don't hesitate to contact us again if you have further questions.

Regards,
Svetoslav
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Atif shahzad
Top achievements
Rank 1
answered on 06 Sep 2014, 02:28 PM
First of all thank you so much for the response, Well i have very complex scenario which i need to explain it in more detail.

I have headings on left side of the document and each heading have descriptions like given below.

Skin: This is normal.

Eyes: No problem found.

Now if user click on hyperlink like Skin/Eyes so i want to get the description of particular item.

If user click on Skin so i want to select the Skin description only.

If user click on Eyes so i wan to to select the Eyes description only.

I have done that and my algorithm works fine if description does not contain any special character like  
, . ;  :  / , If description contain any special character so it does not work correctly i have attached two images kindly help me it is very critical for my application Thanks.

 

 
0
Svetoslav
Telerik team
answered on 10 Sep 2014, 04:07 PM
Hello Atif,

Actually I am still not sure why you need to select every single word separately. If you are trying to extract some text I would suggest to read the document by paragraphs and implement some logic for the extracted text with the methods of String:
DocumentPosition position = new DocumentPosition(this.radRichTextBox.Document);
 
do
{
DocumentPosition paragraphEndPosition = new DocumentPosition(position);
paragraphEndPosition.MoveToLastPositionInParagraph();
this.radRichTextBox.Document.Selection.AddSelectionStart(position);
this.radRichTextBox.Document.Selection.AddSelectionEnd(paragraphEndPosition);
position = paragraphEndPosition;
while(position.MoveToNext()); 
 
string text = this.radRichTextBox.Document.Selection.GetSelectedText();
 
Alternatively here is how to get the text of a line:
DocumentPosition position = new DocumentPosition(this.radRichTextBox.Document);
 
do
{
DocumentPosition lineEndPosition = new DocumentPosition(position);
lineEndPosition.MoveToCurrentLineEnd();
this.radRichTextBox.Document.Selection.AddSelectionStart(position);
this.radRichTextBox.Document.Selection.AddSelectionEnd(lineEndPosition);
position = lineEndPosition ;
 } while(position .MoveToNext());

string text = this.radRichTextBox.Document.Selection.GetSelectedText();

Please let me know if you need further assistance.

Regards,
Svetoslav
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Atif shahzad
Top achievements
Rank 1
answered on 10 Sep 2014, 08:48 PM
Got it, Now i have only one issue left regarding Find/Replace.
If i want to Find  string which contains circle brackets () so find function does not work in code behind, it only works if i use find/replace dialog but i want to find using Code behind sample code are given below.

1.foreach (var textRange in search.FindAll("We are (fine)"))
2.       {
3.           this.MacroRichTextBox.Document.Selection.AddSelectionStart(textRange.StartPosition);
4.           this.MacroRichTextBox.Document.Selection.AddSelectionEnd(textRange.EndPosition);
5.            this.radRichTextBox.Insert("Hurra!");
6.       }
0
Svetoslav
Telerik team
answered on 12 Sep 2014, 04:06 PM
Hi Atif,

The FindAll() method uses the accepted search string as a regex. That said, you can simply escape your search string. More information is available in the Search article.

I hope this helps. 

Regards,
Svetoslav
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Atif shahzad
Top achievements
Rank 1
answered on 17 Sep 2014, 08:45 PM
Thank you so much it really helps.
Tags
RichTextBox
Asked by
Atif
Top achievements
Rank 1
Answers by
Svetoslav
Telerik team
Atif shahzad
Top achievements
Rank 1
Share this question
or