As per your requirement I have written the following code snippet. It may help. Anyways why have you got such requirement?
I have used the following HTML file (testtable.html) :
<html>
<body>
<table border="1" id="mytable" width="300px">
<tr><td>16</td><td>17</td><td>18</td><td>19</td></tr>
<tr><td>32</td><td>34</td><td>36</td><td>38</td></tr>
<tr><td>48</td><td>51</td><td>54</td><td>57</td></tr>
<tr><td>64</td><td>68</td><td>72</td><td>76</td></tr>
<tr><td>80</td><td>85</td><td>90</td><td>95</td></tr>
</table>
</body>
</html>
PART 1 : Loading the HTML file in WebBrowser Control :
Method 1: by hosting it in any webserver :
webBrowser1.Url = new Uri("http://10.10.10.10/testtable.html");
Method 2: by loading from a local html file :
FileStream fs= File.Open(@"D:\Programming Bench\WindowsFormsApplication1\WindowsFormsApplication1\testtable.html",FileMode.Open);
webBrowser1.DocumentStream = fs;
PART 2 : Get data from WebBrowser Control and load to DataGridView
private void btnGetDataFromWebBrowserCtrl_Click(object sender, EventArgs e)
{
HtmlElement mytable = webBrowser1.Document.GetElementById("mytable");
DataTable dtData = new DataTable();
dtData.Columns.Add("column1");
dtData.Columns.Add("column2");
dtData.Columns.Add("column3");
dtData.Columns.Add("column4");
dtData.AcceptChanges();
DataRow dr = null;
foreach (HtmlElement row in mytable.GetElementsByTagName("tr"))
{
dr = dtData.NewRow();
HtmlElementCollection cells = row.GetElementsByTagName("td");
for (int i = 0; i < cells.Count; i++)
{
dr[i] = cells[i].InnerText;
}
dtData.Rows.Add(dr);
}
dtData.AcceptChanges();
dataGridView1.DataSource = dtData;
}
Hope this helps !!