OK... but all that will do is create the HTML into a file, and as you aren't retrieving the returned value you aren't going to be able to do anything more.
How do you normally retrieve the return value from a function?
Printable View
OK... but all that will do is create the HTML into a file, and as you aren't retrieving the returned value you aren't going to be able to do anything more.
How do you normally retrieve the return value from a function?
then what to do sir.......
Here is my code:
When i run the code an exception is thrown......Code:Imports System.Data
Imports System.Data.OleDb
Imports system.io
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Gautam\Documents\Visual Studio 2005\Projects\waste1\waste1\db1.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Table1", myConnection)
Dim ds As DataSet = New DataSet
DataGridView1.Columns(0).DataPropertyName = "Name"
DataGridView1.Columns(1).DataPropertyName = "Address"
DataGridView1.Columns(2).DataPropertyName = "Roll"
da.Fill(ds, "Table1")
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
Private Function RenderListAsHTML(ByRef DataGrid As DataGridView) As String
Dim swrOutput As StreamWriter
' Dim sFormat As String
Dim sPath As String
'establish a temporary filename
sPath = Path.GetTempFileName
swrOutput = New StreamWriter(sPath)
swrOutput.WriteLine("<head>")
swrOutput.WriteLine("<title>Your Title Here</title>")
swrOutput.WriteLine("</head>")
swrOutput.WriteLine("<style type='text/css'>")
swrOutput.WriteLine("th")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("tr")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("</style>")
swrOutput.WriteLine("<body>")
swrOutput.WriteLine("<table>")
'column headers
For Each dvgHeader As DataGridViewColumn In DataGrid.Columns
swrOutput.WriteLine("<th bgcolor='silver'>" & dvgHeader.HeaderText & "</th>")
Next
'actual data
For Each dvgRow As DataGridViewRow In DataGrid.Rows
If dvgRow.Visible Then
swrOutput.Write("<tr>")
For Each objCell As DataGridViewCell In dvgRow.Cells
swrOutput.WriteLine("<td>" & objCell.Value.ToString & "</td>")
Next
swrOutput.Write("</tr>")
End If
Next
swrOutput.WriteLine("</table>")
swrOutput.WriteLine("</body>")
swrOutput.Flush()
swrOutput.Close()
Return sPath
End Function
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.RenderListAsHTML(DataGridView1)
End Sub
End Class
Attachment 72080
How to rectify this sir?
Are there any empty cells in the gridview? If so you may need to trap that.
Try putting a breakpoint on the first "For Each" line and step through the code and see if the error occurs on the first cell or if it is part way through the grid (ie does it get as far as the first "Next").
In the above code sir when the loop goes to this line for the thied time:Code:If dvgRow.Visible Then
swrOutput.Write("<tr>")
For Each objCell As DataGridViewCell In dvgRow.Cells
swrOutput.WriteLine("<td>" & objCell.Value.ToString & "</td>")
Next
swrOutput.Write("</tr>")
End If
Next
then the exception is thrown..........Code:swrOutput.WriteLine("<td>" & objCell.Value.ToString & "</td>")
My design is like this:
Attachment 72081
How to correct this exception sir?
OK it looks like it is treating the "New Entry" row as an actual row, which I didn't realise it would do.
You can get around it by changing the code like this :
Code:If dvgRow.Visible And Not dvgRow.IsNewRow Then
swrOutput.Write("<tr>")
For Each objCell As DataGridViewCell In dvgRow.Cells
swrOutput.WriteLine("<td>" & objCell.Value.ToString & "</td>")
Next
swrOutput.Write("</tr>")
End If
When i click the print button...no error......no output also...
Do i need to add reference to render html?
look at this sir....
Attachment 72083
Here is my full code:
What to do sir........Code:Imports System.Data
Imports System.Data.OleDb
Imports system.io
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Gautam\Documents\Visual Studio 2005\Projects\waste1\waste1\db1.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Table1", myConnection)
Dim ds As DataSet = New DataSet
DataGridView1.Columns(0).DataPropertyName = "Name"
DataGridView1.Columns(1).DataPropertyName = "Address"
DataGridView1.Columns(2).DataPropertyName = "Roll"
da.Fill(ds, "Table1")
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
Private Function RenderListAsHTML(ByRef DataGrid As DataGridView) As String
Dim swrOutput As StreamWriter
' Dim sFormat As String
Dim sPath As String
'establish a temporary filename
sPath = Path.GetTempFileName
swrOutput = New StreamWriter(sPath)
swrOutput.WriteLine("<head>")
swrOutput.WriteLine("<title>Your Title Here</title>")
swrOutput.WriteLine("</head>")
swrOutput.WriteLine("<style type='text/css'>")
swrOutput.WriteLine("th")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("tr")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("</style>")
swrOutput.WriteLine("<body>")
swrOutput.WriteLine("<table>")
'column headers
For Each dvgHeader As DataGridViewColumn In DataGrid.Columns
swrOutput.WriteLine("<th bgcolor='silver'>" & dvgHeader.HeaderText & "</th>")
Next
'actual data
For Each dvgRow As DataGridViewRow In DataGrid.Rows
If dvgRow.Visible And Not dvgRow.IsNewRow Then
swrOutput.Write("<tr>")
For Each objCell As DataGridViewCell In dvgRow.Cells
swrOutput.WriteLine("<td>" & objCell.Value.ToString & "</td>")
Next
swrOutput.Write("</tr>")
End If
Next
swrOutput.WriteLine("</table>")
swrOutput.WriteLine("</body>")
swrOutput.Flush()
swrOutput.Close()
Return sPath
End Function
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.RenderListAsHTML(DataGridView1)
End Sub
End Class
You need to go back and look at posts #59 and #61 where I explained that you now need to open up the file that you've created.
I cant follow you sir....
I have not created any file externally sir.........
Is the file automatically created when i run this code somewhere?
I cant get your point sir......
I am sorry again......
That whole procedure I gave you creates a file, and it returns the name of the file it has created.
Where should i get the file name and the file sir?
I have not given any path in my code sir..........
Then how to get the file?
I cant get ur point sir...............
should i need to do some more coding sir?
please help me sir!!!!!!!
Do you understand any of the code?
This
Gets a temporary filename (as it says in the comment) and thisCode:'establish a temporary filename
sPath = Path.GetTempFileName
returns the filename it has used to the calling function.Code:Return sPath
I'm sure you know that to get a return value from a function you assign the result to a variable, for example :
So in order to get (in your button_click event) the name of the file that was created by the RenderListasHTML function, you need to do something similar...Code:Dim myValue as integer = DoSomeCalculation(1, 2)
Double post
where to place this code sir?Code:Dim myValue as integer = DoSomeCalculation(1, 2)
Please trust me sir........my head is totally locked now...........Now i just want to run the program anyhow......thats it....or i will be dead......Its kind enough enough of you that you are guiding me so much......wasting your time for me sir............
Please tell where to add this line:
Code:Dim myValue as integer = DoSomeCalculation(1, 2)
are you asking me to do this?Code:Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.RenderListAsHTML(DataGridView1)
Dim myValue As Integer = RenderListAsHTML()
End Sub
No...
RenderListAsHTML returns a string - the filename that it has created.
How would you normally get a string back from a function?
Should i do this sir..........Code:Dim myValue As String = RenderListAsHTML()
??????
Well half there... you still need to pass in the datagridview.
Dim myValue as string = RenderListAsHTML(DataGridView1)
That will give you the filename of the HTML file that has been created.
Now... do you want to display the HTML in a browser or just print it out?
This is my entire code sir.........pls check once is it correct or not.......Code:Imports System.Data
Imports System.Data.OleDb
Imports system.io
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Gautam\Documents\Visual Studio 2005\Projects\waste1\waste1\db1.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Table1", myConnection)
Dim ds As DataSet = New DataSet
DataGridView1.Columns(0).DataPropertyName = "Name"
DataGridView1.Columns(1).DataPropertyName = "Address"
DataGridView1.Columns(2).DataPropertyName = "Roll"
da.Fill(ds, "Table1")
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
Private Function RenderListAsHTML(ByRef DataGrid As DataGridView) As String
Dim swrOutput As StreamWriter
' Dim sFormat As String
Dim sPath As String
'establish a temporary filename
sPath = Path.GetTempFileName
swrOutput = New StreamWriter(sPath)
swrOutput.WriteLine("<head>")
swrOutput.WriteLine("<title>Your Title Here</title>")
swrOutput.WriteLine("</head>")
swrOutput.WriteLine("<style type='text/css'>")
swrOutput.WriteLine("th")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("tr")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("</style>")
swrOutput.WriteLine("<body>")
swrOutput.WriteLine("<table>")
'column headers
For Each dvgHeader As DataGridViewColumn In DataGrid.Columns
swrOutput.WriteLine("<th bgcolor='silver'>" & dvgHeader.HeaderText & "</th>")
Next
'actual data
For Each dvgRow As DataGridViewRow In DataGrid.Rows
If dvgRow.Visible And Not dvgRow.IsNewRow Then
swrOutput.Write("<tr>")
For Each objCell As DataGridViewCell In dvgRow.Cells
swrOutput.WriteLine("<td>" & objCell.Value.ToString & "</td>")
Next
swrOutput.Write("</tr>")
End If
Next
swrOutput.WriteLine("</table>")
swrOutput.WriteLine("</body>")
swrOutput.Flush()
swrOutput.Close()
Return sPath
End Function
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.RenderListAsHTML(DataGridView1)
Dim myValue As String = RenderListAsHTML(DataGridView1)
End Sub
End Class
I would like to print it first(Tats my task for tomorrow)......
That looks OK at first glance, but obviously I can't test it.
In order to print it I would create a webbrowser control, navigate to the file (you have the filename now) and then use the webbrowser.print method. The catch is waiting until until the document has loaded into the webbrowser.
Please help me sir........
ok sir then how to do this........Please help me......
Actually no its still wrong.
That first line is pointless, your 2nd line calls the function. If you leave that first line in then it will create two HTML files representing your grid, the first one you then ignore.Code:Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.RenderListAsHTML(DataGridView1)
Dim myValue As String = RenderListAsHTML(DataGridView1)
End Sub
I'm taking a break for an hour or so - see how far you get with creating a webbrowser and getting it to open up your HTML and I'll check back in a bit.
I think its right now sir...Code:Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myValue As String = RenderListAsHTML(DataGridView1)
End Sub
Still I need your help sir in creating a browser and printing it......
I am waiting over here sir..........
OK... how far have you got?
Here is my code sir......Code:Imports System.Data
Imports System.Data.OleDb
Imports system.io
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Gautam\Documents\Visual Studio 2005\Projects\waste1\waste1\db1.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Table1", myConnection)
Dim ds As DataSet = New DataSet
DataGridView1.Columns(0).DataPropertyName = "Name"
DataGridView1.Columns(1).DataPropertyName = "Address"
DataGridView1.Columns(2).DataPropertyName = "Roll"
da.Fill(ds, "Table1")
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
Private Function RenderListAsHTML(ByRef DataGrid As DataGridView) As String
Dim swrOutput As StreamWriter
' Dim sFormat As String
Dim sPath As String
'establish a temporary filename
sPath = Path.GetTempFileName
swrOutput = New StreamWriter(sPath)
swrOutput.WriteLine("<head>")
swrOutput.WriteLine("<title>Your Title Here</title>")
swrOutput.WriteLine("</head>")
swrOutput.WriteLine("<style type='text/css'>")
swrOutput.WriteLine("th")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("tr")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("</style>")
swrOutput.WriteLine("<body>")
swrOutput.WriteLine("<table>")
'column headers
For Each dvgHeader As DataGridViewColumn In DataGrid.Columns
swrOutput.WriteLine("<th bgcolor='silver'>" & dvgHeader.HeaderText & "</th>")
Next
'actual data
For Each dvgRow As DataGridViewRow In DataGrid.Rows
If dvgRow.Visible And Not dvgRow.IsNewRow Then
swrOutput.Write("<tr>")
For Each objCell As DataGridViewCell In dvgRow.Cells
swrOutput.WriteLine("<td>" & objCell.Value.ToString & "</td>")
Next
swrOutput.Write("</tr>")
End If
Next
swrOutput.WriteLine("</table>")
swrOutput.WriteLine("</body>")
swrOutput.Flush()
swrOutput.Close()
Return sPath
End Function
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myValue As String = RenderListAsHTML(DataGridView1)
End Sub
End Class
Now what to do?
I mean with the webbrowser aspect - thats where you were about an hour ago isn't it?
I hope you weren't just waiting for me to come back - I'm not really into writing every line of code for people, especially if it is an assignment.
I know that sir.....If i were not into that excel then i might have tried it from yesterday....
But now its the last moment.....I am helpless and very afraid......about this printing.....
I need your help sir.......Please help me sir for today at least.......
Well the quick and dirty way to do it would be to add a web-browser control to your form and make it invisible.
Then in your button2_click event you would call the webbrowser control's navigate method, passing in the filename of your HTML file.
Then once it is loaded you call its print method. Then you delete the HTML file so you aren't littering your machine's temp folder with old files.
The nicer way to do it would be to create the webbrowser control dynamically but that requires slightly more advanced coding and I'm not sure either of us have the inclination to do that at this point!
You gave me the entire coding till now sir......
I you can give me the dynamically creating web browser code then also i might do it......I wont sleep today even and I might do it........
Now you say sir which way to go now....
I need your help sir.........
If it is for an assignment I'd say rather you just do it the quick and dirty way as I'm sure you can do this easily enough yourself, rather than me giving you code that you don't understand.
If you want to try your own code and post it I'll help you out where you are stuck. Either way to tackle it, there are only something like 5 lines of code to write!
Ok sir ........If there is something 5 lines of code to create it dynamically.....Then i think i should go for the dynamic creation sir.......
First let me try out the code......Then i might understand it today.....
Then only go to bed else no ......
But I need your help sir....Please
OK so how do you create a control dynamically? Bear in mind that controls are just classes.
First please give me the concept of creating dynamically sir.....
You will have done this many times before, but maybe you didn't realise what you were doing.
Say you have defined a class called MyType, and you want to create an object of this type :
Controls aren't really any different, so at its simplest you just needCode:Dim myVariable = New MyType
will create a new webbrowser control and just hold it in memory (it won't appear on any form). You need to place this declaration in the local variables declaration space (ie between the "Public Class Form1" line and your first button click event.Code:Dim myWebBrowser = New WebBrowser
This declaration will need some modification which I will explain shortly once you've set up your control to load up the HTML file.
Once that has been declared you can access it from within the Button2_click event - after you've made the call to create the HTML file.
Ok sir ....
I added this code in between the "Public Class Form1" line and first "button click" event
Now what should i do?Code:Public Class Form1
Dim myWebBrowser = New WebBrowser
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Now sir how to set up control to load up the HTML file?
If you scroll back up to post #92 I told you there how to get a webbrowser control to load a page... and in post #98 I told you where to do it.
Are you talking about this web custom control?
Attachment 72084
I added this sir and a code appears under the "webCustomControl1.vb"
am i right sir?Code:Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
<DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")> _
Public Class WebCustomControl1
Inherits WebControl
<Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property Text() As String
Get
Dim s As String = CStr(ViewState("Text"))
If s Is Nothing Then
Return String.Empty
Else
Return s
End If
End Get
Set(ByVal Value As String)
ViewState("Text") = Value
End Set
End Property
Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)
output.Write(Text)
End Sub
End Class
Then what should I do sir?
How to make the web custom control invisible sir?
Nope - way off the mark I'm afraid. You don't need to add anything new - you've already created the webbrowser control - thats what that last line did.
Now you want to use the webbrowser that you have created - myWebBrowser - to navigate to your HTML file.
There's a big hint in that last sentence as to what you need to do...
In this code i created the control.......Code:Dim myWebBrowser = New WebBrowser
Now i want to use the myWebBrowser.......
am i right sir?
Now what should i do sir.......
Yes thats where we were back up at post #100 and as I replied there to look at posts #92 and #98
I am getting your point sir....
But how and where to make the web browser control invisible sir?
Now in button2_click event I would call the webbrowser control's navigate method, passing in the filename of the HTML file
How to do this sir?
I cant get it........Please help me
Is this what you asked me to do?Code:Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myValue As String = RenderListAsHTML(DataGridView1)
WebBrowser.NavigateEventArgs()
End Sub
No. For a start WebBrowser isn't the name of the webbrowser control you created, it is the name of the class.
What is the name of the webbrowser you just created?
You don't need to make it invisible because it has never been made visible.Quote:
But how and where to make the web browser control invisible sir?
Help me sir.............please
Please give me the code first......let me run it.......check it .........then i will make my concept clear.....Code:mywebbrowser
I am rather getting confuder sir..........
My heart beat is also getting up because its late night here and i have to finish this .........
here lies my entire code sir.....Code:Imports System.Data
Imports System.Data.OleDb
Imports system.io
Public Class Form1
Dim myWebBrowser = New WebBrowser
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Gautam\Documents\Visual Studio 2005\Projects\waste1\waste1\db1.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Table1", myConnection)
Dim ds As DataSet = New DataSet
DataGridView1.Columns(0).DataPropertyName = "Name"
DataGridView1.Columns(1).DataPropertyName = "Address"
DataGridView1.Columns(2).DataPropertyName = "Roll"
da.Fill(ds, "Table1")
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
Private Function RenderListAsHTML(ByRef DataGrid As DataGridView) As String
Dim swrOutput As StreamWriter
' Dim sFormat As String
Dim sPath As String
'establish a temporary filename
sPath = Path.GetTempFileName
swrOutput = New StreamWriter(sPath)
swrOutput.WriteLine("<head>")
swrOutput.WriteLine("<title>Your Title Here</title>")
swrOutput.WriteLine("</head>")
swrOutput.WriteLine("<style type='text/css'>")
swrOutput.WriteLine("th")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("tr")
swrOutput.WriteLine("{")
swrOutput.WriteLine("font: 8pt verdana")
swrOutput.WriteLine("}")
swrOutput.WriteLine("</style>")
swrOutput.WriteLine("<body>")
swrOutput.WriteLine("<table>")
'column headers
For Each dvgHeader As DataGridViewColumn In DataGrid.Columns
swrOutput.WriteLine("<th bgcolor='silver'>" & dvgHeader.HeaderText & "</th>")
Next
'actual data
For Each dvgRow As DataGridViewRow In DataGrid.Rows
If dvgRow.Visible And Not dvgRow.IsNewRow Then
swrOutput.Write("<tr>")
For Each objCell As DataGridViewCell In dvgRow.Cells
swrOutput.WriteLine("<td>" & objCell.Value.ToString & "</td>")
Next
swrOutput.Write("</tr>")
End If
Next
swrOutput.WriteLine("</table>")
swrOutput.WriteLine("</body>")
swrOutput.Flush()
swrOutput.Close()
Return sPath
End Function
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myValue As String = RenderListAsHTML(DataGridView1)
WebBrowser.NavigateEventArgs()
End Sub
End Class
Right - your new control is called MyWebBrowser. So you use that.
The method for Navigating to a page is called Navigate. And it needs to be told what file or URL to navigate to, so you need to pass it the name of the file we just created.
But sir which file to pass in this code?Code:Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myValue As String = RenderListAsHTML(DataGridView1)
myWebBrowser.NavigateEventHandler()
End Sub
Please help me sir......Code:myWebBrowser.NavigateEventHandler()
Firstly.. it is "Navigate" not "NavigateEventHandler" that you need.
Then what you need to tell it is where to look for the HTML, and the line above sets the location of the HTML file we created into a variable called MyValue.
So how about "myWebBrowser.Navigate(MyValue)"?
Then what you need to do is work out how you can tell when it has finished loading the HTML into the browser. How do you reckon -in general terms - what kind of mechansim you need for that? Ie how to controls notify you when something has happened to them?
How should i indicate the finishing of the HTML into the browser sir?Code:Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myValue As String = RenderListAsHTML(DataGridView1)
myWebBrowser.Navigate(myValue)
End Sub
I dont know sir.......
next what to do sir?
OK the answer to my question is... Events...
What event does the webbrowser control raise that may help us here? For some help here's the relevant page on the MSND
Is it the navigated event sir?
Am i right?
Now what to do?
Not quite - that event fires when it gets to the page you want and starts downloading it, you actually want documentcompleted which fires when it has finished downloading the page.
In order to use events with your newly created webbrowser you need to slightly modify your declaration from
to this :Code:Dim myWebBrowser = New WebBrowser
So if you make that change, then in the left-hand dropdown box at the top of the code pane in your code editor, you should see "MyWebBrowser". Click on that and then click in the right-hand dropdown and pick DocumentComplete and it will create this code for you :Code:Dim WithEvents MyWebBrowser As New WebBrowser
Then inside that block you need to get the webbrowser control to print, using one of its built in methods - I'll leave it to you to work out which one.Code:Private Sub MyWebBrowser_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles MyWebBrowser.DocumentCompleted
End Sub