Hello

I've posted a few days ago how to get my data in a SQL database and show it in a datagridview. I found out how to do this rather quickly however I've been asked if I can add a button to my form and be able to print my datagridview.

My code to show the datagrid:

        Dim id As String
        Dim prognaam As String
        Dim fout As String
        Dim sdrFoutregistratie As SqlClient.SqlDataReader

        Dim tblFoutvermelding As New DataTable
        Dim scmdOpenDatabase As New SqlClient.SqlCommand

        tblFoutvermelding.Columns.Add("Id")
        tblFoutvermelding.Columns.Add("Prognaam")
        tblFoutvermelding.Columns.Add("Fout")

        cnnFoutvermeldingSQL.Open()
        scmdOpenDatabase.Connection = cnnFoutvermeldingSQL
        scmdOpenDatabase.CommandText = "SELECT Id, Prognaam, fout FROM Registratietabel ORDER BY Id"
        sdrFoutregistratie = scmdOpenDatabase.ExecuteReader

        Do While sdrFoutregistratie.Read

            id = sdrFoutregistratie.GetValue(0).ToString
            prognaam = sdrFoutregistratie.GetValue(1).ToString
            fout = sdrFoutregistratie.GetValue(2).ToString

            tblFoutvermelding.Rows.Add()
            tblFoutvermelding.Rows(tblFoutvermelding.Rows.Count - 1)("Id") = id
            tblFoutvermelding.Rows(tblFoutvermelding.Rows.Count - 1)("Prognaam") = prognaam
            tblFoutvermelding.Rows(tblFoutvermelding.Rows.Count - 1)("Fout") = fout

        Loop

        DataGridView1.DataSource = tblFoutvermelding
        cnnFoutvermeldingSQL.Close()

So my question is how i'm able to add a print function to the form.

Recommended Answers

All 4 Replies

Google is your friend here. Example. of many.
EDIT: Just realized that it is not VB code in the example I gave you. But believe me you will find plenty of VB examples too.

I've just found a way to print, however it only prints a small selection of the datagridview, it feels like it just takes a screenshot of the datagrid and prints that, any suggestions how I can print the entire datagrid instead of a small selection of it

Look for a code that prints many pages.

Please read this post carefully. You can get more resources from here about printing in tabuler format.

Be a part of the DaniWeb community

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