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

Re-Selection of text throws 'inline does not belong to this document'

6 Answers 130 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 16 Feb 2012, 09:45 PM

The original issue was that when the application was alt tabbed away from and then back to after they had copied text from somewhere else to paste where their cursor is in the radrichtextbox, the cursor moved.  The solution to this was to create 2 methods in the control that we have wrapped around the radrichtextbox, the first one is called at the beginning of the lost focus and the second one is 2 lines of code later after the text is pulled into the data context.  The cursor position works fine but it now loses selection when right clicking because right click fires lostfocus which resets the cursor position.  Here is the attempt to re-select the selection (assuming 1 text selection area).  The storing works but the re-setting blows up.

        private PointF _position;

        private DocumentPosition _start;

        private DocumentPosition _end;

       

        public void StoreCaretPosition()

        {

            _position = rtArea.Document.CaretPosition.Location;

            if (rtArea.Document.Selection.Ranges.First != null)

            {

                _start = new DocumentPosition(rtArea.Document.Selection.Ranges.First.StartPosition);

                _end = new DocumentPosition(rtArea.Document.Selection.Ranges.First.EndPosition);

            }

        }

        public void RestoreCaretPosition()

        {

            rtArea.Document.CaretPosition.SetPosition(_position);

            rtArea.Document.Selection.AddSelectionStart(_start);

            rtArea.Document.Selection.AddSelectionEnd(_end);

        }

The error we are getting is after adding the end selection it blows up on the method’s end curly bracket with the error ‘inline does not belong to this document.’

6 Answers, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 17 Feb 2012, 06:42 PM
Hello Eric,

We could not reproduce your issue. We would very much appreciate if you can send us a demo project demonstrating the unusual behavior with pressing alt+tab.
On the other hand you can try saving the start and end position of the selection as PointF too.

PointF _start = rtArea.Document.Selection.Ranges.First.StartPosition.Location;
and then 
DocumentPosition startDocumentPosition = new DocumentPosition(this.rtArea.Document);
startDocumentPosition.SetPosition(_start);

and one more thing. The right way to set selection programatically is to use SetSelectionStart method 
(instead of AddSelectionStart) first and then AddSelectionEnd.

Hope we helped in a way. Please get back to us, if you can't resolve your problem. Regards,
Andrew
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Eric
Top achievements
Rank 1
answered on 17 Feb 2012, 07:42 PM
Changing the code from 'Add' to 'Set' worked for me.  Thank you.
Eric
0
Venkat
Top achievements
Rank 1
answered on 24 Sep 2012, 06:14 AM
We are having One Silverlight Text Box and one Rich Text Box UI on my xaml page.

Once I select  Text from the TextBox and then  I focused my Cursor on Teleric's Rich Text BOX ,then the selection from the Silverlight Text Box is loosing (Expected behavior).

Once I select text from Teleric's Rich Text Box UI and then when I focus my cursor on Silverlight's Text Box , the selection from the Rich Text Box is not losing..! it still selected. when I have selected text from Silver light Text Box, then also the Rich Text Box text selection remains same. Now I am having two selections , this is not expected.If I press Ctl+C i am confused from which text box the text is copied to clip board.

So my requirement is to un select the text selection on Rich Text box , when it looses focus,but when I do this, even when I click on Ribbon buttons, the selection is losing...! How can I achieve this.?

Even if I write  logic to clear the selection of Rich Text Box on Text Box's got focus event , but I don't know after loosing the focus on Rich Text Box where the user points his cursor, so if my page has so many controls , then i need to add this logic to all controls, but this is not a good solution , i think.

my Rad control version is 2011.1.149.1040.

Thanks
Venkat
0
Iva Toteva
Telerik team
answered on 25 Sep 2012, 04:16 PM
Hi Venkat,

We have this item as a feature request, but it has not been implemented yet.

You can use this PITS issue to vote for this feature and track our progress:
You can follow the PITS Issue by its ID: 12759
Public Url: http://www.telerik.com/support/pits.aspx#/public/silverlight/12759 


All the best,
Iva Toteva
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
danparker276
Top achievements
Rank 2
answered on 30 Jul 2013, 06:12 PM
I am also getting this error sometimes.  Is it safe to just replace all the AddSelectionStart with SetSelectionStart
0
Iva Toteva
Telerik team
answered on 01 Aug 2013, 07:22 AM
Hello Dan,

Please refer to 
this forum thread for a more elaborate explanation of the way the selection methods work in general and in particular in the way you seem to be using them.


Regards,
Iva Toteva
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
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
Asked by
Eric
Top achievements
Rank 1
Answers by
Andrew
Telerik team
Eric
Top achievements
Rank 1
Venkat
Top achievements
Rank 1
Iva Toteva
Telerik team
danparker276
Top achievements
Rank 2
Share this question
or