bonsoir,

j'essaie d'imprimer les données d'un datagrid en lisant un dataset correspondant à ce datagrid

j'ai utilisé le tutoriel d'impression de Jm Rabilloud que j'ai adapté à mon application mais j'ai un petit soucis.

Je reçois le message d'exception suivant:

L'exception System.ArgumentException n'a pas été gérée
Message="PageSetupDialog a besoin d'un objet PageSettings pour s'afficher. Définissez PageSetupDialog.Document (par défaut), PageSetupDialog.PrinterSettings ou PageSetupDialog.PageSettings."



Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
        'paramétrage
        With Me.PrintDocument1.DefaultPageSettings
            .Landscape = True
            .Color = False
            .Margins = New Printing.Margins(ConvTo(10), ConvTo(10), ConvTo(10), ConvTo(10))
        End With
        'bloque les boutons de selection d'imprimante et l'orientation
        With Me.PageSetupDialog1
            .AllowMargins = True
            .AllowOrientation = False
            .AllowPaper = True
            .AllowPrinter = False
            If System.Globalization.RegionInfo.CurrentRegion.IsMetric Then
                .MinMargins = New Printing.Margins(ConvTo(10), ConvTo(10), ConvTo(10), ConvTo(10))
            End If
        End With
 
        If Me.PageSetupDialog1.ShowDialog(Me) = Windows.Forms.DialogResult.Cancel Then
 
            If MessageBox.Show("Voulez vous abandonner l'impression", "Annulation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) = Windows.Forms.DialogResult.OK Then
                Exit Sub
            End If
        End If
        ReDim TabImpr.TabLarg(7)
        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\dbccw.mdb"
        strSql = "SELECT Max(Len([annee])) as lannee, Max(Len([nom]) as lnom, Max(Len([prenom]) as lprenom, Max(Len([adresse]) as ladresse, Max(Len([cp]) as lcp, Max(Len([ville]) as lville FROM Contact WHERE ag=true"
        ObjetConnection = New OleDbConnection()
        ObjetConnection.ConnectionString = strConn
        ObjetConnection.Open()
        'Récupération des longueurs de chaines
        Dim dtrTaille As OleDbDataReader = ObjetCommand.ExecuteReader(CommandBehavior.SingleRow)
        dtrTaille.Read()
        For cmpt As Double = 0 To 5
            TabImpr.TabLarg(cmpt) = dtrTaille.GetInt32(cmpt)
        Next
        dtrTaille.Close()
        'Récupération du nombre de ligne
        ObjetCommand.CommandText = "SELECT COUNT(nom) FROM Contact"
        TabImpr.NbRow = CInt(ObjetCommand.ExecuteScalar)
        ObjetConnection.Close()
        Me.PrintPreviewDialog1.ShowDialog()
L'exception apparait à la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
If Me.PageSetupDialog1.ShowDialog(Me) = Windows.Forms.DialogResult.Cancel Then

Pourriez-vous m'aider pour gérer cette erreur ?

Merci

Olivier