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 :

Ajouter la barre de total en bas du datagridview


Sujet :

VB.NET

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Webmaster
    Inscrit en
    Décembre 2017
    Messages
    34
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Décembre 2017
    Messages : 34
    Points : 29
    Points
    29
    Par défaut Ajouter la barre de total en bas du datagridview
    Bonjour ,

    comment j'ajoute comme cette ligne de total en bas du datagridview qui sera stable même si l'utilisateur utilise le scrollbar ?

    Nom : Capture.PNG
Affichages : 361
Taille : 10,9 Ko
    Merci d'avance.

  2. #2
    Membre confirmé Avatar de thierry007
    Homme Profil pro
    Autodidacte
    Inscrit en
    Août 2006
    Messages
    876
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Autodidacte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2006
    Messages : 876
    Points : 457
    Points
    457
    Par défaut
    Bonjour

    A Première vue elle ne fait pas partie du datagrid, mais d'un second limité a une ligne. Ce dernier reçoit les valeur de calcul du premier datagridview
    La Connaissance est comme la joie elle s'accroît en la partageant!

  3. #3
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    Tu peux ajouter des Controls en bas du dgv pour les totaux ...
    voici un code exemple succinct de ce qu'il y a lieu de se taper comme 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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
     
    Imports System.Data.OleDb
     
    Public Class FormTotalControl
        Private lbTotal As Label = New Label()
        Private tbPrix As TextBox = New TextBox()
        Private tbPrixTTC As TextBox = New TextBox()
     
        'index des colonnes concernées
        Dim colID As Integer
        Dim colPrix As Integer
        Dim colTaxe As Integer
        Dim colPrixTTC As Integer 'colonne calculée en vol
     
     
        Private dt As New DataTable
        Private da As New OleDbDataAdapter
        Private conn As New OleDbConnection
        Private Sub FormTotalControl_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\HUSSEIN\Desktop\WinDGV\WinSubTotalDGV\StockProduits.mdb;Persist Security Info=True"
            ' select command
            da.SelectCommand = New OleDbCommand("SELECT ID, Prix, Taxe, PrixTTC  FROM Produits")
            da.SelectCommand.Connection = conn
     
     
     
            da.Fill(dt)
            Me.dgv.DataSource = dt
     
            ' recupere  index des colonnes concernées
            colID = Me.dgv.Columns(0).Index
            colPrix = Me.dgv.Columns(1).Index
            colTaxe = Me.dgv.Columns(2).Index
            colPrixTTC = Me.dgv.Columns(3).Index
     
            'ajout des controls en bas du dgv
            AddControls()
     
     
     
     
     
        End Sub
        Private Sub AddControls()
            lbTotal.Text = "Total"
            lbTotal.BorderStyle = BorderStyle.FixedSingle
            lbTotal.BackColor = Color.Red
            lbTotal.ForeColor = Color.Yellow
     
            lbTotal.Height = tbPrix.Height
            lbTotal.AutoSize = False
            lbTotal.TextAlign = ContentAlignment.MiddleCenter
     
            Dim X As Integer = Me.dgv.GetCellDisplayRectangle(colID, -1, True).Location.X
            lbTotal.Width = Me.dgv.Columns(colID).Width
            lbTotal.Location = New Point(X, Me.dgv.Height - lbTotal.Height)
            Me.dgv.Controls.Add(lbTotal)
     
            tbPrix.BorderStyle = BorderStyle.FixedSingle
            tbPrix.ForeColor = Color.Red
            tbPrix.Width = Me.dgv.Columns(colPrix).Width
            X = Me.dgv.GetCellDisplayRectangle(colPrix, -1, True).Location.X
            tbPrix.Location = New Point(X, Me.dgv.Height - tbPrix.Height)
            Me.dgv.Controls.Add(tbPrix)
     
            tbPrixTTC.BorderStyle = BorderStyle.FixedSingle
            tbPrixTTC.ForeColor = Color.Red
            tbPrixTTC.Width = Me.dgv.Columns(colPrixTTC).Width
            X = Me.dgv.GetCellDisplayRectangle(colPrixTTC, -1, True).Location.X
            tbPrixTTC.Location = New Point(X, Me.dgv.Height - tbPrixTTC.Height)
            Me.dgv.Controls.Add(tbPrixTTC)
        End Sub
     
        Private Sub DGV_CellPainting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgv.CellPainting
            If e.RowIndex < 0 Or e.ColumnIndex < 0 Then Return
            Dim prix As Double
            Dim taxe As Double
            Dim prixTTC As Double
     
            Dim totalPrix As Double = 0.0
            Dim totalPrixTTC As Double = 0.0
     
            For i As Integer = 0 To Me.dgv.Rows.Count - 2
                prix = 0.0
                prixTTC = 0.0
                taxe = 0.0
                If Not IsDBNull(Me.dgv(colPrix, i).Value) Then
                    prix = Convert.ToDouble(Me.dgv(colPrix, i).Value)
                End If
     
                If Not IsDBNull(Me.dgv(colTaxe, i).Value) Then
                    taxe = Convert.ToDouble(Me.dgv(colTaxe, i).Value)
                End If
     
                prixTTC = prix * (1 + taxe / 100)
                Me.dgv(colPrixTTC, i).Value = prix * (1 + taxe / 100)
     
     
                totalPrix += prix
                totalPrixTTC += prixTTC
            Next
            tbPrix.Text = totalPrix.ToString()
            tbPrixTTC.Text = totalPrixTTC.ToString()
            lbTotal.Update()
            tbPrix.Update()
            tbPrixTTC.Update()
     
            'Dim X As Integer = Me.dgv.GetCellDisplayRectangle(colID, -1, True).Location.X
            'lbTotal.Width = Me.dgv.Columns(0).Width
            'lbTotal.Location = New Point(0, Me.dgv.Height - lbTotal.Height)
            'lbTotal.Text = "Total"
     
            'tbPrix.Width = Me.dgv.Columns(colPrix).Width
            'X = Me.dgv.GetCellDisplayRectangle(colPrix, -1, True).Location.X
            'tbPrix.Location = New Point(X, Me.dgv.Height - tbPrix.Height)
     
            'tbPrixTTC.Width = Me.dgv.Columns(colPrixTTC).Width
            'X = Me.dgv.GetCellDisplayRectangle(colPrixTTC, -1, True).Location.X
            'tbPrixTTC.Location = New Point(X, Me.dgv.Height - tbPrixTTC.Height)
     
        End Sub
     
    End Class
    NB : la bd StockProduits est en pièce jointe ...
    bon code...

Discussions similaires

  1. Réponses: 2
    Dernier message: 04/07/2015, 15h24
  2. Réponses: 7
    Dernier message: 15/02/2006, 17h13
  3. [JToolBar] ajouter une barre d'outil à un JApplet
    Par romuluslepunk dans le forum Composants
    Réponses: 4
    Dernier message: 09/08/2005, 03h36
  4. [MFC] Ajouter une barre de message à un CDialog
    Par annedjomo dans le forum MFC
    Réponses: 7
    Dernier message: 09/05/2005, 13h45
  5. Ajouter une barre d'outils à une sous fenêtre
    Par barthelv dans le forum MFC
    Réponses: 6
    Dernier message: 23/04/2004, 14h17

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