IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Impression inversé d'une DataGrid


Sujet :

VB.NET

  1. #1
    Membre très actif
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2013
    Messages
    121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2013
    Messages : 121
    Par défaut Impression inversé d'une DataGrid
    Re Bonjour les amis

    Mon problème aujourd’hui c'est l’impression inversé d'une DataGrid. Résumant un peut, j'ai un DataGrid remplie à partir de la Base de donnée et qui s'affiche correctement de droite à gauche (les données s'affichent en Arabe), tout est parfait pour le moment (colonne(0), colonne(1), colonne(2), colonne(3))

    Le problème c'est lors de l'impression que les champs s'inversent (colonne(3), colonne(2), colonne(1), colonne(0)).

    voila mon code à rectifier s'il le faut

    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
     
    '------------------------- Choix de l'imprimante ----------------------
            'Dim dlg As New PrintDialog
            'dlg.Document = PrintDocument1
            'Dim result As DialogResult = dlg.ShowDialog() = PrintPreviewDialog1.ShowDialog()
            'If (result = System.Windows.Forms.DialogResult.OK) Then
            '    PrintDocument1.Print()
            'End If
            '---------------------------------------------------------------------
     
     '-------------- visualisation du document Avant Impression ------------
            PrintPreviewDialog1.Document = PrintDocument1
            PrintPreviewDialog1.PrintPreviewControl.Zoom = 1.1
            AddHandler PrintDocument1.PrintPage, AddressOf PrintDocument1_PrintPage
            PrintPreviewDialog1.WindowState = FormWindowState.Maximized
            PrintPreviewDialog1.ShowDialog() 
           '--------------------------------------------------------------------------
        End Sub
     
     
        Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
     
            With DataGridView1
                Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
                fmt.SetDigitSubstitution(New Globalization.CultureInfo("Ar").LCID, StringDigitSubstitute.National)
                fmt.FormatFlags = StringFormatFlags.DirectionRightToLeft
                fmt.Trimming = StringTrimming.EllipsisCharacter
                fmt.LineAlignment = StringAlignment.Near
                Dim y As Single = e.MarginBounds.Top
     
                Do While mRow < .RowCount - 1
                    Dim row As DataGridViewRow = .Rows(mRow) 
                    Dim x As Single = e.MarginBounds.Left
                    Dim h As Single = 0
                    For Each cell As DataGridViewCell In row.Cells
                        Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, cell.Size.Height)
                        e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height) ' Cadriage du tableau
                        If (newpage) Then
                            e.Graphics.DrawString(DataGridView1.Columns(cell.ColumnIndex).HeaderText, .Font, Brushes.Black, rc, fmt)
                        Else
                            e.Graphics.DrawString(DataGridView1.Rows(cell.RowIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), .Font, Brushes.Black, rc, fmt)
                        End If
                        x += rc.Width  'espacement entre les colones de 1.1
                        h = Math.Max(h, rc.Height) 'espacement entre les lignes de 1.1
                        'x += 1.1 * rc.Width 'espacement entre les colones de 1.1
                        'h = Math.Max(h, rc.Height) * 1.1 'espacement entre les lignes de 1.1
                    Next
                    newpage = False
                    y += h
                    mRow += 1
                    If y + h > e.MarginBounds.Bottom Then
                        e.HasMorePages = True
                        mRow -= 1
                        newpage = True
                        Exit Sub
                    End If
                Loop
                mRow = 0
            End With
        End Sub
    Remarque: Le code fonctionne bien pour les informations Latin

    Mes champs ( CIN , PreNom , Nom , Date de naissance)

    Merci.

  2. #2
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    bonjour

    Tu n'as qu'à inverser l'ordre de parcours des colonnes:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     For k As Integer = row.Cells.Count - 1 To 0 Step -1
                        Dim cell As DataGridViewCell = row.Cells(k)
     
    Next
    Au lieu du foreeach:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    For Each cell As DataGridViewCell In row.Cells
     
     
    Next
    bon code.......

  3. #3
    Membre très actif
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2013
    Messages
    121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2013
    Messages : 121
    Par défaut
    Salut Mabrouki

    ta proposition marche pour moi comme voulue, mais je dois corriger un autre problème avant. je n'ai rendu compte que maintenant et c'est lors de l'impression il manque la premier enregistrement c'est à dire le code imprime l'entête du DataGrid puis commence par le 2 enregistrement (Row(0), Row(2), Row(3)...) il manque le Row(1). C'est étrange ça?

    Merci pour ton aide une autre fois.

Discussions similaires

  1. [QuickReport ]Impression conditionnelle d'une bande
    Par DéGé dans le forum Bases de données
    Réponses: 4
    Dernier message: 17/07/2004, 13h00
  2. [C#] Cacher une colonne d'une dataGrid
    Par royrremi dans le forum ASP.NET
    Réponses: 2
    Dernier message: 27/05/2004, 16h00
  3. Pb d'update dans une DataGrid
    Par bidson dans le forum XMLRAD
    Réponses: 11
    Dernier message: 27/05/2003, 14h11
  4. [VB6] [Impression] Savoir si une imprimante est installée
    Par Norm59ttp dans le forum Installation, Déploiement et Sécurité
    Réponses: 2
    Dernier message: 19/12/2002, 09h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo