WebBrowser Adding a Delete row to a table

Source: Internet
Author: User

1. Modify the form: \ui\docinfo\document.cs


private void Menutableadd_click (object sender, EventArgs e) {
Htmleditor.tableaddrow (htmldesign);
}

private void Menutabledel_click (object sender, EventArgs e) {
Htmleditor.tabledeleterow (htmldesign);
}

2. Modify Class: HtmlEditor.cs


public static void Tableaddrow (WebBrowser pWb) {
int rowIndex = 0;
HTMLTable table = getselecttable (pWb, ref rowIndex);
if (table! = null) {
int collen = Table.cells.length/table.rows.length;
HtmlTableRow row = (HtmlTableRow) table.insertrow (RowIndex);
for (int i = 0; i < Collen; i++) {
Object Elcell = Row.insertcell (i);
HtmlTableCell cell = (HtmlTableCell) Elcell;
Cell.innertext = "";
}
}

       }
        public static void Tabledeleterow (WebBrowser pWb) {
             int rowIndex = 0;
            HTMLTable table = getselecttable (pWb, ref RowIndex);
            if (table! = null) {
                 Table.deleterow (RowIndex);
           }
       }

public static HTMLTable getselecttable (WebBrowser pwb,ref int prowindex) {
Mshtml. IHTMLDocument2 doc2 = (mshtml. IHTMLDocument2) pWb.Document.DomDocument;
Mshtml. IHTMLTxtRange rangeobj = (mshtml. IHTMLTxtRange) (Doc2.selection.createRange ());

Mshtml. IHTMLElement ele = Rangeobj.parentelement ();
int rowIndex = 0;
if (ele! = null) {
for (int i = 0; i <; i++) {
if (ele = = null) break;
if (ele.tagName.ToLower () = = "Table") {
Break
}
if (ele.tagName.ToLower () = = "tr") {
HtmlTableRow tr = (htmltablerow) ele;
RowIndex = Tr.rowindex;
}
Ele = ele.parentelement;
}
}
if (ele! = null && ele.tagName.ToLower () = = "Table") {
Prowindex = RowIndex;
Return (HTMLTable) ele;
}
else {
return null;
}
}


WebBrowser Adding a Delete row to a table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.