473,472 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to RemoveChild from HtmlElement from C#

Vin
Hi,

I have a webbrowser control in my winform. There is an html in the
webbrowser which has a table, and many child <tr>s and <td>s inside it.
I want to delete a specific <tr> node completely from the html. (I dont
want to do style = "display:none"). I want to do RemoveChild("id of the
tr") of the table, on some button click.

There is no RemoveChild available on HtmlElement.
MS experts, MVPs....any clues on how to do this?

Cheers,
Vin

Feb 6 '06 #1
3 16364
here is the code: (NOTE: you need to add reference to Microsoft.mshtml
assembly first from the .net tab)

Assuming the web browser control name is "browser"

using mshtml;
private void HandleFormLoad (object sender, EventArgs e)
{
browser.NavigateComplete2 +=new
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Even tHandler
(NavigationComplete);
browser.Navigate2("http://localhost/testtable.html");
}

private void NavigationComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Even t e)
{
HTMLDocumentClass htmlDoc = browser.Document as
HTMLDocumentClass;
IHTMLDOMNode node = htmlDoc.getElementById ("tr2") as
IHTMLDOMNode;
MessageBox.Show ("Click to remove the second row...");
node.parentNode.removeChild (node);
}

//the testtable.html file looks like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET
7.1">
<meta name="ProgId" content="VisualStudio.HTML">
<meta name="Originator" content="Microsoft Visual Studio .NET
7.1">
</head>
<body>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300"
border="1">
<TR id="tr1">
<TD>Row 1 : Col 1</TD>
<TD>Row 1 : Col 2</TD>
<TD>Row 1 : Col 3</TD>
</TR>
<TR id="tr2">
<TD>Row 2 : Col&nbsp;1</TD>
<TD>Row 2 : Col 2</TD>
<TD>Row 2 : Col 3</TD>
</TR>
<TR id="tr3">
<TD>Row 3 : Col 1</TD>
<TD>Row 3 : Col 2</TD>
<TD>Row 3 : Col 3</TD>
</TR>
</TABLE>
</body>
</html>
Hope this helps...

- NuTcAsE

Feb 6 '06 #2
Vin
Hi thanks for that tip.

But, I am using .Net 2.0's WebBrowser control (not AxWebBrowser
control)
and......
HTMLDocumentClass htmlDocument = webBrowser1.Document as
HTMLDocumentClass;

OR

HTMLDocumentClass htmlDocument = (HTMLDocumentClass)
webBrowser1.Document;

result in.....
Error : Cannot convert type 'System.Windows.Forms.HtmlDocument' to
'mshtml.HTMLDocumentClass'

Any clues?
Thanks in advance,

Cheers,
Vin

Feb 6 '06 #3
The WebBrowser.Document is a managed HtmlDocument wrapper, you need to
use the DomDocument property of the HtmlDocument object... code below:

//In the NavigateCompleted event...

HTMLDocumentClass doc = browser.Document.DomDocument as
HTMLDocumentClass;
IHTMLDOMNode node = doc.getElementById ("tr2");
.... //the rest is the same as above.

Hope this helps...
- NuTcAsE

Feb 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason Keirstead | last post by:
Is there a way I can add a setter/getter to the HTMLElement prototype in internet explorer? This, for example, works fine in Mozilla: HTMLElement.prototype.__defineSetter__("foobar", function...
1
by: Christopher Benson-Manica | last post by:
How do you extend HTMLElement? Why can't you just do HTMLElement.prototype.foo=function() { alert( 'foo' ); } I assume HTMLElement belongs to some kind of namespace, but darn if I can find...
1
by: JehanNYNJ | last post by:
I need to clear out the HTML contents of a <span> element and then re-add that element as a blank span. Here is the code... var elem = document.getElementById(spanId); var deletedElem =...
2
by: Stewart | last post by:
Originally posted in comp.lang.javascript: Newsgroups: comp.lang.javascript From: "Stewart" Date: 23 Aug 2005 02:50:04 -0700 Local: Tues, Aug 23 2005 10:50 am Subject: FireFox, RemoveChild,...
1
by: Rebecca Tsukalas | last post by:
Hello, I have a problem concerning removeChild. This is the XML structure I use with php: <xml_thing <language1 <site>bla1</site <site>bla2</site <site>bla3</site </language1
1
by: AMDRIT | last post by:
Hello Everyone, We have a production WinForms Application that uses a WebBrowser to display readonly data. In the html document we have SPAN elements that facilitate menu selections. We also...
10
by: r_ahimsa_m | last post by:
Hello, On index.html page I have a table with id="property_fields". <table id="property_fields" name="property_fields" border="0"> It contains set of rows with the following IDs: var...
5
by: r_ahimsa_m | last post by:
Hello, I am lerning HTML/CSS/JavaScript. I created HTML page with table "property_fields" containing 24 rows ('tr' elements). I want to remove last 23 rows: var table =...
5
by: marchaos | last post by:
I'm trying to override the native HTMLElement.addEventListener in firefox so that I can do some extra things. I know it's possible to add methods to the HTMLElement prototype and for them to be...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.