Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print Contents of DataGrid ? 1

Status
Not open for further replies.
May 22, 2006
16
MY
hi everybody,

Who have the idea to Print Contents of DataGrid by using vb.net? look like print data in the document!



Regards,
charles

 
You need to change some part of the code in above example as given in FAQ's at the bottom of the same page.


Sharing the best from my side...

--Prashant--
 
hi everyone,

For the above question which i already solved, but not really completed! because if the contents of datagrid is very large/ big which mean the value is very big then the output still can't to full print out, because of limitation page width size report !

So, i got following the idea but i don't know how to do it...
which i want to export this contents of datagrid to microsoft excel. so how can i do for this? any suggestion, please help!

Thanks a lot!

Regards,
charles
 
Yes...That example prints if the contents are less and fitting to your page width. If you do paging on the contents, then you can print that page.
Exporting to Excel format seems nice one, but if the contents are really large, then this will consume more time to export in Excel format and then print.

Sharing the best from my side...

--Prashant--
 
Thank you reply, pgorule!

Yes... my contents are really large. So, do you have this idea for export contents of DataGrid to excel file with VB.NET ??

thanks for ur help!

Regards,
charles



 
I just finished some work for this...here is simple code:
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim excel As New Excel.Application()
        excel.Application.Workbooks.Add(True)
        Dim dt As New DataTable()
        dt = Me.NorthwindDataSet.Tables(0)
        Dim cInd As Integer = 0
        For Each dc As DataColumn In dt.Columns
            cInd = cInd + 1
            excel.Cells(1, cInd) = dc.ColumnName
        Next
        Dim rInd As Integer = 0
        For Each dr As DataRow In dt.Rows
            rInd = rInd + 1
            cInd = 0
            For Each dc As DataColumn In dt.Columns
                cInd = cInd + 1
                excel.Cells(rInd + 1, cInd) = dr(dc.ColumnName).ToString
            Next
        Next
    End Sub

here you need to add COM reference for Ms-Excel Object library. Here I'm using a Dataset (NorthwindDataSet) that filled the DataGrid. You can save this document if you want before exiting from Sub.
Hope you will find this code helpful.

Sharing the best from my side...

--Prashant--
 
Thank you a lot!

I got the error which "Type 'Excel.Application" is not defined!!!

For the above that you mention about need to add COM reference for Ms-Excel Object library.
So, How to add this? Sorry, give you a lot of trouble!
Because i still very fresh to learn this vb.net!

Thank you!

Regards,
charles
 
In solution explorer:
Find References...if not there Click on 'Show all files' button present in solution explorer window.
Right click on references...and Add Reference
In the dialog select COM tag.
Scroll down to get Microsoft Excel xx.x Object library - xx.x being the version number.
Say 'OK' and enjoy the code...

Sharing the best from my side...

--Prashant--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top