vb 水晶报表打印

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

报表设计:

运行效果:

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值