Hi, all....
There is a RadRichTextBox and want to select text from the Document object based on two positions, 2 parameters: initial position of the character and end character position. That is, the two parameters are only numbers.
Is this possible?
Thanks alls
There is a RadRichTextBox and want to select text from the Document object based on two positions, 2 parameters: initial position of the character and end character position. That is, the two parameters are only numbers.
Is this possible?
Thanks alls
5 Answers, 1 is accepted
0
Hi Xavendano,
You can use DocumentTextMap class for mapping text positions to document positions with the help of MapFromIndexInText method.
Kind regards,
Boby
the Telerik team
You can use DocumentTextMap class for mapping text positions to document positions with the help of MapFromIndexInText method.
Kind regards,
Boby
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0
Romell
Top achievements
Rank 1
answered on 16 Jul 2012, 03:59 PM
Hi Boby and thanks....I try the following code (vb,net / WPF WebBrowser Application):
1: Dim documentMap As New DocumentTextMap(Me.myRadRichTextBox.Document)
2: Dim textRange As TextRange = documentMap.MapFromIndexInText(2, 4)
3: Me.myRadRichTextBox.Document.Selection.AddSelectionStart(textRange.StartPosition)
4: Me.myRadRichTextBox.Document.Selection.AddSelectionStart(textRange.EndPosition)
The line 2 show the following error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Why? Because the line 1 while Im creating the documentMap Object, this is empty:
Error - No children available.
But, the radRich control I'snt not empty, they had a single line with multiple words.....why the line 1 do that??
How can I fix this?
Thanks alls
1: Dim documentMap As New DocumentTextMap(Me.myRadRichTextBox.Document)
2: Dim textRange As TextRange = documentMap.MapFromIndexInText(2, 4)
3: Me.myRadRichTextBox.Document.Selection.AddSelectionStart(textRange.StartPosition)
4: Me.myRadRichTextBox.Document.Selection.AddSelectionStart(textRange.EndPosition)
The line 2 show the following error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Why? Because the line 1 while Im creating the documentMap Object, this is empty:
Error - No children available.
But, the radRich control I'snt not empty, they had a single line with multiple words.....why the line 1 do that??
How can I fix this?
Thanks alls
0
Accepted
Hello Romell,
Kind regards,
Martin
the Telerik team
You need to initialize the map with document positions. Also your selection must have start and end.
Here is an example:
Dim
documentMap
As
New
DocumentTextMap(
Me
.myRadRichTextBox.Document)
Dim
pos1
As
New
DocumentPosition(
Me
.myRadRichTextBox.Document)
Dim
pos2
As
New
DocumentPosition(
Me
.myRadRichTextBox.Document)
pos2.MoveToNextInline()
pos2.MoveToNextInline()
documentMap.InitMap(pos1, pos2)
Dim
textRange
As
TextRange = documentMap.MapFromIndexInText(1, 5)
Me
.myRadRichTextBox.Document.Selection.AddSelectionStart(textRange.StartPosition)
Me
.myRadRichTextBox.Document.Selection.AddSelectionEnd(textRange.EndPosition)
Kind regards,
Martin
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0
Romell
Top achievements
Rank 1
answered on 21 Aug 2012, 08:28 PM
Hi Martin,
how I can get the exact opposite?
I mean, given a choice of a text in a RadRichTextBox, how I can get the first and second index that defines the selection made.
Example: "THE HOUSE IS GREEN"
When I select the word "HOUSE", I get : pos1 = 4 and pos2 = 9.
Thanks ...
how I can get the exact opposite?
I mean, given a choice of a text in a RadRichTextBox, how I can get the first and second index that defines the selection made.
Example: "THE HOUSE IS GREEN"
When I select the word "HOUSE", I get : pos1 = 4 and pos2 = 9.
Thanks ...
0
Romell
Top achievements
Rank 1
answered on 29 Aug 2012, 09:16 PM
Mmmmm Any ideas???