Am trying to search a specific Text in the Document, and replace it with Table.
this is what am doing:
private void Replace()
{
this.radRichTextBox1.Document.Selection.Clear();
DocumentTextSearch ser = new DocumentTextSearch(this.radRichTextBox1.Document);
IList<DocumentPosition> startPositions = new List<DocumentPosition>();
IList<DocumentPosition> endPositions = new List<DocumentPosition>();
foreach (var textRange in ser.FindAll("<Threat"))
startPositions.Add(textRange.StartPosition);
foreach (var textRange in ser.FindAll(KEYEND))
endPositions.Add(textRange.EndPosition);
string xml = string.Empty;
for (int i = 0; i < startPositions.Count; i++)
{
this.radRichTextBox1.Document.Selection.Clear();
this.radRichTextBox1.Document.Selection.AddSelectionStart(startPositions[i]);
this.radRichTextBox1.Document.Selection.AddSelectionEnd(endPositions[i]);
xml = this.radRichTextBox1.Document.Selection.GetSelectedText();
Table tbl = GenerateTable(xml);
this.radRichTextBox1.InsertTable(tbl);
}
but it doesn't work. when i try to replace the selection with any string, it works fine. what's wrong??? please help
this is what am doing:
private void Replace()
{
this.radRichTextBox1.Document.Selection.Clear();
DocumentTextSearch ser = new DocumentTextSearch(this.radRichTextBox1.Document);
IList<DocumentPosition> startPositions = new List<DocumentPosition>();
IList<DocumentPosition> endPositions = new List<DocumentPosition>();
foreach (var textRange in ser.FindAll("<Threat"))
startPositions.Add(textRange.StartPosition);
foreach (var textRange in ser.FindAll(KEYEND))
endPositions.Add(textRange.EndPosition);
string xml = string.Empty;
for (int i = 0; i < startPositions.Count; i++)
{
this.radRichTextBox1.Document.Selection.Clear();
this.radRichTextBox1.Document.Selection.AddSelectionStart(startPositions[i]);
this.radRichTextBox1.Document.Selection.AddSelectionEnd(endPositions[i]);
xml = this.radRichTextBox1.Document.Selection.GetSelectedText();
Table tbl = GenerateTable(xml);
this.radRichTextBox1.InsertTable(tbl);
}
but it doesn't work. when i try to replace the selection with any string, it works fine. what's wrong??? please help