I try to split an HTML section according to the selection point. For example suppose I have :
<table>
<tr><td> one </td></tr>
<tr><td> two </td></tr>
<tr><td> tree </td></tr>
</table>
Now if the user selects two
with mouse and click on a split button, I should have :
<table>
<tr><td> one </td></tr>
</table>
And
<table>
<tr><td> two </td></tr>
<tr><td> tree </td></tr>
</table>
It can occur on any other element too (P
, div
, ...), and on any nested element.
I tried the following C# code:
IHTMLDocument2 doc =
webBrowser1.Document.DomDocument as IHTMLDocument2;
IHTMLBodyElement body = doc.body as IHTMLBodyElement;
if (doc.selection != null)
{
if (doc.selection.type == "Text")
{
range = doc.selection.createRange() as IHTMLTxtRange;
range.moveEnd("textedit");
// NOW range.htmlText gives me the second part,
// however I don't know how to extract it from the section
// and remain the first part
}
}
Now range.htmlText gives me the second fragment completely (with the parent tags), however I don't know how to extract it from the section and leave the first fragment?! execCommand("cut")
may do the job, however if selection spans on several table rows that trick doesn't work.
Or any other solution?