Taking Printout from Datagrid.

Joined
Jan 20, 2006
Messages
6
Programming Experience
Beginner
Hi friends!
I am working on project in which I am using Vb.Net 2003 Pro. and SQL Server 2000. My problem is that after filtering the database using SQL Query I want to take the print out of the filtered database which can be seen in the datagrid. Is there any procedure to take the printout of datagrid in the form of report generation.
Can any one help me Plz.
 
Not inherently, you have to manage the printing in the regular .Net fashion yourself - or you can get a custom datagrid control with printing capabilities (I think there is one free at The Code Project). The exist also some number free 'amateur' classes to use/modify that will provide printouts for a given datagrid. If you search "print datagrid" here at the forum + at some web search engine, you should be able to find something usable.
 
Here's the way I did the very same thing.

I had a datagrid (Component One TrueDBGrid) with a filter bar on the top. The filterbar filtered and sorted a large dataset down to the records I needed. Once I had only the records I wanted I wanted to print out a list of those records.

I created a dataset that was Identical to the one I sorted, (dragging an SQLDataAdapter and creating select statements with the wizard) I just never fill it.

I created a public datatable: this will be set to the dummy dataset just created
Public tblTemp1 As DataTable

Then I loop through the datagrid and add the fields to tblTemp1 and set that table as the crystal report datasource. Note: I never save the tblTemp1 or the dataset dsTemp1 to the server, they only exist in memory while the program is running.

VB.NET:
        [COLOR=Green]'Find the number of records left in the filtered grid.[/COLOR]
        Dim c As Integer = Me.BindingContext(DsGage1, "Gage").Count
        [COLOR=Green]'set the datagrid row to 0 here[/COLOR]
        Dim i As Integer
        tblTemp1 = DsTemp1.Tables("Gage")
        [COLOR=Green]' Clearing the table before loading is important![/COLOR]
        tblTemp1.Clear()
        Dim drCurrentTG As DataRow
        If c > 0 Then
            For i = 1 To c
                Try
                    drCurrentTG = tblTemp1.NewRow()
                    [COLOR=Green]' assign values from the grid to the new table[/COLOR]
                    [COLOR=Green]'drCurrentTG("column1") = your grid column value etc[/COLOR]
                    tblTemp1.Rows.Add(drCurrentTG)
                Catch ex As Exception
                    'do nothing 
                End Try
               [COLOR=Green] ' Increment the grid's row here[/COLOR]
            Next
        Else
            MsgBox("No Gages Selected")
        End If



       [COLOR=Green] ' Set the reports datasource to the loaded temp table.[/COLOR]
        Dim TempListRpt As New rptTempList1
        TempListRpt.SetDataSource(tblTemp1)
        [COLOR=Green]' preview or print the report here[/COLOR]



Update the code to set the grid row to 0
Update the code to add the fields of the datagrid to the table
Update the code to increment the datagrid row by 1

My code is different for the ComponentOne datagrid.


Hope that helps.
 
damn, I just re-read your post.
You already have a filtered dataset.
Just setup a public table and 'Push' that table to a Crystal Report.

Sorry, It is easier than my example.

Research Crystal reports push methods and you should have a great printout.

Public tblTemp1 As DataTable

tblTemp1 = DsTemp1.Tables("Gage")' Change this to your Table

' This PUSHES the table to the report
Dim TempListRpt As New rptTempList1
TempListRpt.SetDataSource(tblTemp1)


 
Back
Top