Hi,
In the RadRichTextBox I'm working with, I am listening to the SelectionChanged event when the user selects a piece of a string. I need to determine, within the span.Text in which the string is located, what is the position (index) within the Span.Text of the selected string.
So, for example, if the span.Text contains "This is a piece of text"
and the user selects "piece"
I want to write code that returns "10", which is the index of "piece" within "This is a piece of text"
I have tried various properties that I hoped would get me this number - eg
var range = t.Document.Selection.Ranges.First;
if (range != null)
{
string curSpanText = t.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan.Text;
string s = t.Document.Selection.GetSelectedText();
int start = range.StartPosition.GetCurrentPositionInSpan();
int end = range.EndPosition.GetCurrentPositionInSpan();
}
I hoped that "start" above would give me what I needed but it doesn't.
s gets me the string I had selected. curSpanText is the entire span's Text property. How do I find the position of s within curSpanText?
Thanks
In the RadRichTextBox I'm working with, I am listening to the SelectionChanged event when the user selects a piece of a string. I need to determine, within the span.Text in which the string is located, what is the position (index) within the Span.Text of the selected string.
So, for example, if the span.Text contains "This is a piece of text"
and the user selects "piece"
I want to write code that returns "10", which is the index of "piece" within "This is a piece of text"
I have tried various properties that I hoped would get me this number - eg
var range = t.Document.Selection.Ranges.First;
if (range != null)
{
string curSpanText = t.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan.Text;
string s = t.Document.Selection.GetSelectedText();
int start = range.StartPosition.GetCurrentPositionInSpan();
int end = range.EndPosition.GetCurrentPositionInSpan();
}
I hoped that "start" above would give me what I needed but it doesn't.
s gets me the string I had selected. curSpanText is the entire span's Text property. How do I find the position of s within curSpanText?
Thanks