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.

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.

Edited 1 Year Ago by ddanbe: correction

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

This article has been dead for over six months. Start a new discussion instead.