vb里面的水晶报表打印控件:CrystalReportViewer

用到的dll文件:

水晶报表打印其实很简单,只要创建报表对象,再对其传递数据就可以打印出来。当然所传递的数据要与水晶报表设计里面的数据一致:

Public Overloads Sub ShowDialog(ByVal netDs As DataSet, ByVal strPath As String, Optional ByVal showPrint As Boolean = True, Optional ByVal showExport As Boolean = True)
        Try
            If netDs.Tables(0).Rows.Count > 0 Then
                Dim rpt As New ReportDocument
                rpt.Load(strPath)
                rpt.SetDataSource(netDs)

                CRV.ReportSource = rpt
                CRV.ShowPrintButton = showPrint
                CRV.ShowExportButton = showExport
                Dim t As New ComboBox
                t.Visible = True
                ShowDialog()
            Else
                MsgBox("Not print Data!", MsgBoxStyle.Critical)
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

调用例子:在其他设计界面,当要打印之时,直接传递参数到打印界面即可。

Dim daOM As SqlDataAdapter
    Dim cmbOM As SqlCommandBuilder
    Dim dsOM As New DataSet

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            daOM = New SqlDataAdapter("select top 5 * from facd321 ", GetConn)
            cmbOM = New SqlCommandBuilder(daOM)

            daOM.Fill(dsOM, "OM")

            With dg
                .DataSource = dsOM.Tables("OM")
                .WindowLaguage = myDataGrid.myDatagrid.LanguageType.English
                .FilterBar = True
                Dim ii As Int16
                For ii = 0 To .Splits(0).DisplayColumns.Count - 1
                    .Splits(0).DisplayColumns(ii).Locked = True
                Next
            End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
        End Try
    End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Me.Cursor = Cursors.WaitCursor

            Dim f As New Form1
            AddBarcodeImages(dsOM.Tables(0))
            f.ShowDialog(dsOM, Application.StartupPath & "\Reports\bundle.rpt")
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

报表设计:

运行效果:

 

posted on 2013-09-12 12:54  vinsonLu  阅读(5622)  评论(1编辑  收藏  举报