Hi. I'm trying to print from datagridview but I don't understand how to do it. I've found some coding and this is the best for me.


But the tutorial is using server and I'm using this to call my table from Acces to datagridview. I don't know where to replace the tutorial with my coding.

Imports System.Data.OleDb

    Dim con As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String
    Dim dv As DataView

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As DataSet
        Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\~LaiLi~\My Documents\Visual Studio 2005\Projects\MoreWever\MoreWever\bin\Debug\Inventory.mdb"
        Dim cn As OleDbConnection

        cn = New OleDbConnection(ConStr)
        ds = New DataSet
        dv = New DataView
        Dim ad As New OleDbDataAdapter("SELECT * FROM Sales", cn)
        ad.Fill(ds, "Sales")
        dv.Table = ds.Tables("Sales")
        Me.DataGridView1.DataSource = dv

    End Sub

I don't understand [Public Function GetData() As DataView] part. And when I try the coding, though the PrintPreviewDialog shown nothing, it open a window that I have to choose something from it. That part I don't understand too. Or maybe you guys have other codings, I really appreciate it. Please check it for me. Thank you.

Recommended Answers

why dont you use crystal report?

Jump to Post

All 2 Replies

why dont you use crystal report?

Check out this code sample, this will allow you to export your datagrid to an excel file, then you can print from excel. That may be easier for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.