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 :

Réaliser un planning en Datagridview avec cellpaint


Sujet :

VB.NET

  1. #1
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut Réaliser un planning en Datagridview avec cellpaint
    Bonjour à tous,

    Tout d'abord, mon programme est fait en framework 2
    J'ai crée un Datagridview journalier. Chaque colonne représente un intervalle de 10min :

    0h 10 20 30 40 50 1h 10 20 30 40 50 3h 10 20 30 40 50 etc...
    J'ai ensuite ajouter des rows qui corrspondent à des salles :

    Salle 1
    Salle 2
    Salle 3

    Pour remplir ce tableau, je me connecte à une base access, d'où j'extrais la date et heure de début, la date et heure de fin et le prénom de la personne qui occupera la salle. En fonction de la date choisi dans un datetimepicker, je souhaite que mon tableau journalier se remplisse.
    J'ai vu qu'on peut utiliser cellpaint :
    http://msdn.microsoft.com/fr-fr/libr...lpainting.aspx

    Seulement dans mon cas, je peux avoir plusieurs possibilités :
    - jour début < date choisie et jour fin > date choisie
    - jour début < date choisie et jour fin = date choisie
    - jour début = date choisie et jour fin = date choisie
    - jour début = date choisie et jour fin > date choisie

    Ensuite se greffe les heures dans les cas ou jour début ou jour fin = date choisie.

    Dans la plupart des cas, mon cellpaint risque de couvrir plusieurs cellules en non une seule.
    Est-t-il possible avec cet évènement de ne faire qu'un seul rectangle qui contiendrait le prénom de la personne qui couvrirait tout mon fuseau horaire pour l'exemple :
    jour début < date choisie et jour fin > date choisie
    (C'est à dire de 0h à 23h59)

    Pour les autres exemples, le principe resterait le même : couvrir plusieurs cellules avec un seul rectangle ...

    Si possible, comment faire ?

    Merci pour vos futures réponses et suggestions

  2. #2
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Regarde le début de cette discussion : http://www.developpez.net/forums/d89...g+datagridview
    " Le croquemitaine ! Aaaaaah ! Où ça ? " ©Homer Simpson

  3. #3
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Hello Graffito,

    J'avais lu ce topic mais je t'avoue qu'avec mon niveau de connaissances, je suis totalement largué
    Mon datagridview qui s'affichera ne sera pas modifiable. Ce n'est qu'un genre d'aperçu journalier en fonction des données de ma base access.

    Dûr dûr.....


    bon j'ai pris le code msdn pour faire un essai . Il me fait bien un rectangle bleu avec le contenu de la cellule en rouge pour une colonne prédéfini.

    J'ai parcouru le Topic que tu m'as suggéré mais je suis incapable de savoir comment faire déborder mon rectangle en fonction des conditions sur plusieurs cellules d'une même ligne ....

  4. #4
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Re,

    Bon ben j'y arrive toujours pas. De + le code du Topic est en C.
    Personne a une idée en partant du code msdn comment faire un seul rectangle sur plusieurs cellules d'une même ligne.

    De +, il existe très peu de doc sur cet évènement

  5. #5
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Convertisseur C# vers Vb.net ici : http://www.carlosag.net/tools/codetranslator/
    " Le croquemitaine ! Aaaaaah ! Où ça ? " ©Homer Simpson

  6. #6
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Re,

    Je dois partir de ce code (post 18) ? :

    http://www.developpez.net/forums/d89...w/#post5119416

    Entre-temps, j'ai réalisé mon tableau avec des flèches toutes moches et le rendu est vraiment pas génial. Je vais voir ce que cela va donner en convertissant en espérant comprendre le contenu et quoi changer ensuite ....

    Je te tiens au jus

  7. #7
    Modérateur
    Avatar de Sankasssss
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2006
    Messages
    1 842
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 842
    Points : 4 232
    Points
    4 232
    Par défaut
    Bonjour,

    Nous avons réalisé quelque chose de similaire pour notre entreprise et nous avons utilisé le SourceGrid :



    trouvé ici et disponible ici

    Il permet de fusionner des cellules, a un très bon rendu et est simple d'utilisation

  8. #8
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Bonjour à tous,

    Je déterre ce sujet car je n'ai toujours pas réussi à faire ce que je voulais en Vbnet. Surement lié à mon niveau ....
    Ce que je cherche ressemblerait à çà :
    http://www.developpez.net/forums/d14...g/#post8019354
    Qui serait alimenté par un tableau datagridview ....

    Il n'existe rien en Vbnet pour mon minable niveau ?

  9. #9
    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

    DataGridView_RowPostPaint peut peindre l'arrière-plan d'un DataGridView entier avec Graphics.fillRectangle(SolidBrush,rowBounds)...

    De plus l'exemple MSDN Help Fr fournit un exemple complet de comment procéder pour peindre un rectangle complet en dessous de chaque ligne ...intitule :
    "Comment : personnaliser l'apparence des lignes du contrôle DataGridView Windows Forms"...
    Il suffit de reprendre cet exemple et de mettre du code à la suite du rectangle intitule textArea pour ajuster son origine via un prop Origin et multiplier son width via un prop exprime en pourcentage de durée :

    extrait du code .vb MSDN du DataGridView_RowPostPaint :

    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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
     
     
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
     
    Class DataGridViewRowPainting
        Inherits Form
        Private WithEvents dataGridView1 As New DataGridView()
        Private oldRowIndex As Int32 = 0
        Private Const CUSTOM_CONTENT_HEIGHT As Int32 = 30
     
        <STAThreadAttribute()> _
        Public Shared Sub Main()
     
            Application.Run(New DataGridViewRowPainting())
     
        End Sub 'Main
     
        Public Sub New()
     
            Me.dataGridView1.Dock = DockStyle.Fill
            Me.Controls.Add(Me.dataGridView1)
            Me.Text = "DataGridView row painting demo"
     
        End Sub 'New
     
        Sub DataGridViewRowPainting_Load(ByVal sender As Object, _
            ByVal e As EventArgs) Handles Me.Load
     
            ' Set a cell padding to provide space for the top of the focus 
            ' rectangle and for the content that spans multiple columns. 
            Dim newPadding As New Padding(0, 1, 0, CUSTOM_CONTENT_HEIGHT)
            Me.dataGridView1.RowTemplate.DefaultCellStyle.Padding = newPadding
     
            ' Set the selection background color to transparent so 
            ' the cell won't paint over the custom selection background.
            Me.dataGridView1.RowTemplate.DefaultCellStyle.SelectionBackColor = _
                Color.Transparent
     
            ' Set the row height to accommodate the normal cell content and the 
            ' content that spans multiple columns.
            Me.dataGridView1.RowTemplate.Height += CUSTOM_CONTENT_HEIGHT
     
            ' Initialize other DataGridView properties.
            Me.dataGridView1.AllowUserToAddRows = False
            Me.dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2
            Me.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None
            Me.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
     
            ' Set the column header names.
            Me.dataGridView1.ColumnCount = 4
            Me.dataGridView1.Columns(0).Name = "Recipe"
            Me.dataGridView1.Columns(0).SortMode = _
                DataGridViewColumnSortMode.NotSortable
            Me.dataGridView1.Columns(1).Name = "Category"
            Me.dataGridView1.Columns(2).Name = "Main Ingredients"
            Me.dataGridView1.Columns(3).Name = "Rating"
     
            ' Hide the column that contains the content that spans 
            ' multiple columns.
            Me.dataGridView1.Columns(2).Visible = False
     
            ' Populate the rows of the DataGridView.
            Dim row1() As String = {"Meatloaf", "Main Dish", _
                "1 lb. lean ground beef, 1/2 cup bread crumbs, " + _
                "1/4 cup ketchup, 1/3 tsp onion powder, 1 clove of garlic, " + _
                "1/2 pack onion soup mix, dash of your favorite BBQ Sauce", "****"}
            Dim row2() As String = {"Key Lime Pie", "Dessert", _
                "lime juice, whipped cream, eggs, evaporated milk", "****"}
            Dim row3() As String = {"Orange-Salsa Pork Chops", "Main Dish", _
                "pork chops, salsa, orange juice, pineapple", "****"}
            Dim row4() As String = {"Black Bean and Rice Salad", "Salad", _
                "black beans, brown rice", "****"}
            Dim row5() As String = {"Chocolate Cheesecake", "Dessert", _
                "cream cheese, unsweetened chocolate", "***"}
            Dim row6() As String = {"Black Bean Dip", "Appetizer", _
                "black beans, sour cream, salsa, chips", "***"}
            Dim rows() As Object = {row1, row2, row3, row4, row5, row6}
            Dim rowArray As String()
            For Each rowArray In rows
                Me.dataGridView1.Rows.Add(rowArray)
            Next rowArray
     
            ' Adjust the row heights to accommodate the normal cell content.
            Me.dataGridView1.AutoResizeRows( _
                DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders)
        End Sub 'DataGridViewRowPainting_Load
     
        ' Forces the control to repaint itself when the user 
        ' manually changes the width of a column.
        Sub dataGridView1_ColumnWidthChanged(ByVal sender As Object, _
            ByVal e As DataGridViewColumnEventArgs) _
            Handles dataGridView1.ColumnWidthChanged
     
            Me.dataGridView1.Invalidate()
     
        End Sub 'dataGridView1_ColumnWidthChanged
     
        ' Forces the row to repaint itself when the user changes the 
        ' current cell. This is necessary to refresh the focus rectangle.
        Sub dataGridView1_CurrentCellChanged(ByVal sender As Object, _
            ByVal e As EventArgs) Handles dataGridView1.CurrentCellChanged
     
            If oldRowIndex <> -1 Then
                Me.dataGridView1.InvalidateRow(oldRowIndex)
            End If
            oldRowIndex = Me.dataGridView1.CurrentCellAddress.Y
     
        End Sub 'dataGridView1_CurrentCellChanged
     
        ' Paints the custom selection background for selected rows.
        Sub dataGridView1_RowPrePaint(ByVal sender As Object, _
            ByVal e As DataGridViewRowPrePaintEventArgs) _
            Handles dataGridView1.RowPrePaint
     
            ' Do not automatically paint the focus rectangle.
            e.PaintParts = e.PaintParts And Not DataGridViewPaintParts.Focus
     
            ' Determine whether the cell should be painted with the 
            ' custom selection background.
            If (e.State And DataGridViewElementStates.Selected) = _
                DataGridViewElementStates.Selected Then
     
                ' Calculate the bounds of the row.
                Dim rowBounds As New Rectangle( _
                    Me.dataGridView1.RowHeadersWidth, e.RowBounds.Top, _
                    Me.dataGridView1.Columns.GetColumnsWidth( _
                    DataGridViewElementStates.Visible) - _
                    Me.dataGridView1.HorizontalScrollingOffset + 1, _
                    e.RowBounds.Height)
     
                ' Paint the custom selection background.
                Dim backbrush As New _
                    System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
                    Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
                    e.InheritedRowStyle.ForeColor, _
                    System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
                Try
                    e.Graphics.FillRectangle(backbrush, rowBounds)
                Finally
                    backbrush.Dispose()
                End Try
            End If
     
        End Sub 'dataGridView1_RowPrePaint
     
        ' Paints the content that spans multiple columns and the focus rectangle.
        Sub dataGridView1_RowPostPaint(ByVal sender As Object, _
            ByVal e As DataGridViewRowPostPaintEventArgs) _
            Handles dataGridView1.RowPostPaint
     
            ' Calculate the bounds of the row.
            Dim rowBounds As New Rectangle(Me.dataGridView1.RowHeadersWidth, _
                e.RowBounds.Top, Me.dataGridView1.Columns.GetColumnsWidth( _
                DataGridViewElementStates.Visible) - _
                Me.dataGridView1.HorizontalScrollingOffset + 1, e.RowBounds.Height)
     
            Dim forebrush As SolidBrush = Nothing
            Try
                ' Determine the foreground color.
                If (e.State And DataGridViewElementStates.Selected) = _
                    DataGridViewElementStates.Selected Then
     
                    forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
                Else
                    forebrush = New SolidBrush(e.InheritedRowStyle.ForeColor)
                End If
     
                ' Get the content that spans multiple columns.
                Dim recipe As Object = _
                    Me.dataGridView1.Rows.SharedRow(e.RowIndex).Cells(2).Value
     
                If (recipe IsNot Nothing) Then
                    Dim text As String = recipe.ToString()
     
                    ' Calculate the bounds for the content that spans multiple 
                    ' columns, adjusting for the horizontal scrolling position 
                    ' and the current row height, and displaying only whole
                    ' lines of text.
                    Dim textArea As Rectangle = rowBounds
                    textArea.X -= Me.dataGridView1.HorizontalScrollingOffset
                    textArea.Width += Me.dataGridView1.HorizontalScrollingOffset
                    textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
                    textArea.Height -= rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
                    textArea.Height = (textArea.Height \ e.InheritedRowStyle.Font.Height) * _
                        e.InheritedRowStyle.Font.Height
     
                    ' Calculate the portion of the text area that needs painting.
                    Dim clip As RectangleF = textArea
                    clip.Width -= Me.dataGridView1.RowHeadersWidth + 1 - clip.X
                    clip.X = Me.dataGridView1.RowHeadersWidth + 1
                    Dim oldClip As RectangleF = e.Graphics.ClipBounds
                    e.Graphics.SetClip(clip)
     
                    ' Draw the content that spans multiple columns.
                    e.Graphics.DrawString(text, e.InheritedRowStyle.Font, forebrush, _
                        textArea)
     
                    e.Graphics.SetClip(oldClip)
                End If
            Finally
                forebrush.Dispose()
            End Try
     
            If Me.dataGridView1.CurrentCellAddress.Y = e.RowIndex Then
                ' Paint the focus rectangle.
                e.DrawFocus(rowBounds, True)
            End If
     
        End Sub 'dataGridView1_RowPostPaint
     
        ' Adjusts the padding when the user changes the row height so that 
        ' the normal cell content is fully displayed and any extra
        ' height is used for the content that spans multiple columns.
        Sub dataGridView1_RowHeightChanged(ByVal sender As Object, _
            ByVal e As DataGridViewRowEventArgs) _
            Handles dataGridView1.RowHeightChanged
     
            ' Calculate the new height of the normal cell content.
            Dim preferredNormalContentHeight As Int32 = _
                e.Row.GetPreferredHeight(e.Row.Index, _
                DataGridViewAutoSizeRowMode.AllCellsExceptHeader, True) - _
                e.Row.DefaultCellStyle.Padding.Bottom()
     
            ' Specify a new padding.
            Dim newPadding As Padding = e.Row.DefaultCellStyle.Padding
            newPadding.Bottom = e.Row.Height - preferredNormalContentHeight
            e.Row.DefaultCellStyle.Padding = newPadding
     
        End Sub
     
    End Class 'DataGridViewRowPainting
    lien MSDN:
    https://www.google.fr/url?sa=t&rct=j...25801520,d.d24

    bon code..............

  10. #10
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Hello MABROUKI,

    Merci pour le lien. Je vais essayer de me dépatouiller dedans même si au premier abord je n'y comprend quasiment rien
    Actuellement çà ressemble à ceci :
    Nom : planning.png
Affichages : 1626
Taille : 11,0 Ko

    C'est vraiment pas joli car je reconstitue les traits et les pseudos flèches avec les caractères du clavier ...

  11. #11
    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

    Voici un exemple tout prêt du comment utiliser l'event RowPaint pour peindre une barre de diagramme en dessous de chaque ligne...(un postulant)...
    L'exemple simule 5 postulants avec chacun une plage date-horaire et suite à une date "piquée" avec le "pique-assiette DTP" ,il calcule la durée "consommable" par chaque postulant ...sous forme d'un pourcentage d'heures répercutée en "barre de longueur proportionnelle"....
    1/ code .vb du class data Person :

    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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
     
    Imports System.Globalization
     
    Public Class Person
     
        Private IDValue As Integer
        Public Property ID() As Integer
            Get
                Return IDValue
            End Get
            Set(ByVal value As Integer)
                IDValue = value
            End Set
        End Property
        Private NameValue As String
        Public Property Name() As String
            Get
                Return NameValue
            End Get
            Set(ByVal value As String)
                NameValue = value
            End Set
        End Property
        'Durée calculée en % d'heures 
        Private DurationPercentValue As Single
        Public Property DurationPercent() As Single
            Get
                Return DurationPercentValue
            End Get
            Set(ByVal value As Single)
                DurationPercentValue = value
            End Set
        End Property
        'Date choisie par le pique-assiete DateTimePicker
        Private ChoiceDateValue As Date = Date.MaxValue
        Public Property ChoiceDate() As Date
            Get
                Return ChoiceDateValue
            End Get
            Set(ByVal value As Date)
                ChoiceDateValue = value
                ComputeWidth(value) 'calcul de la durée
            End Set
        End Property
        Private StartDateValue As Date = Date.MaxValue
        Public Property StartDate() As Date
            Get
                Return StartDateValue
            End Get
            Set(ByVal value As Date)
                StartDateValue = value
            End Set
        End Property
        Private EndDateValue As Date
        Public Property EndDate() As Date
            Get
                Return EndDateValue
            End Get
            Set(ByVal value As Date)
                EndDateValue = value
            End Set
        End Property
     
        Public ReadOnly Property Diagram() As String
            Get
                Return DurationPercent.ToString
            End Get
     
        End Property
        'duree comptabilise en heure dans l'exemple
        Private Sub ComputeWidth(ByVal ChoiceDate As Date)
            If ChoiceDate = Date.MaxValue Then Return 'date de fin du monde 
     
            DurationPercent = 0.0
            Dim ts As TimeSpan = Nothing
     
            If (StartDate < ChoiceDate And EndDate > ChoiceDate) Then
                ts = EndDate.Subtract(ChoiceDate)
                DurationPercent = ts.Hours
            ElseIf (EndDate = ChoiceDate) Then
     
                ts = EndDate.Subtract(ChoiceDate)
                DurationPercent = ts.Hours
            ElseIf (StartDate = ChoiceDate) Then
     
                ts = EndDate.Subtract(ChoiceDate)
                DurationPercent = ts.Hours
            ElseIf (StartDate = ChoiceDate) Then
                ts = StartDate.Subtract(ChoiceDate)
                DurationPercent = ts.Hours
            End If
            DurationPercent = DurationPercent / 100.0  'traduction en %
     
            'ce que j'ai cru comprendre à defaut d'un code explicite
            '- jour début < date choisie et jour fin > date choisie =>   jour début < date choisie < jour fin  =>NbH = jourfin-jourdebut
            '- jour début < date choisie et jour fin = date choisie =>   jour début < date choisie = jour fin  =>NbH = jourfin-datechoisie ou datechoisie -jourfin
            '- jour début = date choisie et jour fin = date choisie =>   jour début = date choisie = jour fin  =>NbH (heures)= jourfin-datechoisie ou datechoisie -jourfin
            '- jour début = date choisie et jour fin > date choisie =>   jour début = date choisie > jour fin  =>NbH (heures)= jourfin-datechoisi
     
     
     
     
     
        End Sub
    End Class
     
     
    Public Class Persons
        Inherits List(Of Person)
        Private produit As Person
        Private rndDay As New Random
        Private rndHour As New Random
        Dim culture As CultureInfo = New CultureInfo("fr-FR", True)
     
        ' l'exemple utilise un planning à la date pivot du 12/07/2016  soit 2 jours avant le 14 kuillet 
     
        Dim s As String = "12/07/2016 12:00:00"
        Dim datePivot As DateTime = DateTime.Parse(s,
                                            culture,
                                            DateTimeStyles.NoCurrentDateDefault)
     
        Public Sub New()
            For index = 1 To 10
                ' dates d'exemple des postulants ocillant  "randomly" de 10 à 15 jours et de 0 à 23 heures (en + ou -)
                'autour de la date "pivot"
                Dim intervalDay As Integer = rndDay.Next(10, 16)
                Dim intervalHour As Integer = rndDay.Next(0, 24)
                Dim t As TimeSpan = New TimeSpan(intervalDay, intervalHour, 0, 0)
     
                produit = New Person() With {.ID = index, .Name = "salle" + index.ToString,
                                              .StartDate = datePivot.Subtract(t),
                                              .EndDate = datePivot.Add(t)}
                Me.Add(produit)
            Next
     
        End Sub
    End Class
    2/ code .vb du Form utilisateur avec un DGV et un DTP droppe dessus :



    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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
     
    Imports System.Drawing
    Imports System.Drawing.Drawing2D
    Public Class PlanningDGV
        Private oldRowIndex As Int32 = 0
        ' Hauteur de ligne en SUS en dessous de la ligne courante
        ' Commune à tout le ROW(son contenu chevauchera plusieurs colonnes) 
        Private Const CUSTOM_CONTENT_HEIGHT As Int32 = 30
        Private l As Persons
        Private Sub FormDGV_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' Ajuste Padding du Style par defaut des  Cellules
            Dim newPadding As New Padding(0, 1, 0, CUSTOM_CONTENT_HEIGHT)
            Me.DataGridView1.RowTemplate.DefaultCellStyle.Padding = newPadding
     
            '  Selection Background Color à transparent voir dessin diagram
            Me.DataGridView1.RowTemplate.DefaultCellStyle.SelectionBackColor =
                Me.DataGridView1.DefaultCellStyle.SelectionBackColor
     
            ' Ajuste Height Total du RowTemplate( Normal  + Hauteur EN SUS) 
            Me.DataGridView1.RowTemplate.Height += CUSTOM_CONTENT_HEIGHT
     
     
            Me.DataGridView1.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders)
            l = New Persons
            RefreshBind()
        End Sub
        Private Sub RefreshBind()
            DataGridView1.DataSource = l
            DataGridView1.Refresh()
        End Sub
     
     
     
        Private Sub DataGridView1_ColumnWidthChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles DataGridView1.ColumnWidthChanged
            Me.DataGridView1.Invalidate()
     
        End Sub
     
        Private Sub DataGridView1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellChanged
            If oldRowIndex <> -1 Then
                Me.DataGridView1.InvalidateRow(oldRowIndex)
            End If
            oldRowIndex = Me.DataGridView1.CurrentCellAddress.Y
     
        End Sub
     
        ' Ajuste  "padding" si  user change hauteur du Row o that 
        ' the normal cell content is fully displayed and any extra
        ' height is used for the content that spans multiple columns.
        Sub dataGridView1_RowHeightChanged(ByVal sender As Object, ByVal e As DataGridViewRowEventArgs) Handles DataGridView1.RowHeightChanged
     
            ' hauteur du Row normale sans "padding"
            Dim preferredNormalContentHeight As Int32 =
                e.Row.GetPreferredHeight(e.Row.Index,
                DataGridViewAutoSizeRowMode.AllCellsExceptHeader, True) - e.Row.DefaultCellStyle.Padding.Bottom()
     
            ' MAJ du "padding".
            Dim newPadding As Padding = e.Row.DefaultCellStyle.Padding
            newPadding.Bottom = e.Row.Height - preferredNormalContentHeight
            e.Row.DefaultCellStyle.Padding = newPadding
     
        End Sub
     
        Private Sub DataGridView1_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
            ' Rzctangle englobant du Row.
            Dim rowBounds As New Rectangle(Me.DataGridView1.RowHeadersWidth,
                e.RowBounds.Top, Me.DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) -
                Me.DataGridView1.HorizontalScrollingOffset + 1,
                e.RowBounds.Height)
     
            Dim backbrush As LinearGradientBrush = Nothing
            Dim forebrush As SolidBrush = Nothing
            Try
                ' Determine the foreground color.
                If (e.State And DataGridViewElementStates.Selected) = DataGridViewElementStates.Selected Then
     
                    forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
                Else
                    forebrush = New SolidBrush(Color.White)
                End If
     
                'Contenu qui "spanne" plusieurs colonnes (le DurationPercent est en colonne 3).
     
                Dim recipe As Object =
                    Me.DataGridView1.Rows(e.RowIndex).Cells(2).Value
                Dim text As String = String.Empty
                If (recipe IsNot Nothing) Then
                    text = (recipe * 100.0F).ToString()  '
                End If
     
                ' Calcul du sous-rectangle englobant du contenu EN SUS(sous-rectangle en dessous)
                Dim textArea As Rectangle = rowBounds
     
                textArea.X -= Me.DataGridView1.HorizontalScrollingOffset
                textArea.Width += Me.DataGridView1.HorizontalScrollingOffset
                textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
                textArea.Height -= rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
                textArea.Height = (textArea.Height / e.InheritedRowStyle.Font.Height) * e.InheritedRowStyle.Font.Height
     
     
     
                ' Calcul par "clipping" pour peindre uniquement la portion necessaire du sous-rectangle .... 
                Dim clip As RectangleF = textArea
                clip.Width -= Me.DataGridView1.RowHeadersWidth + 1 - clip.X
                clip.X = Me.DataGridView1.RowHeadersWidth + 1
                Dim oldClip As RectangleF = e.Graphics.ClipBounds 'sauve rectangle de clipping courant pour restauration)
                e.Graphics.SetClip(clip) '"clippe" le sous-rectangle 
     
                'Dessine un Bar Red  proportionnel à DurationPercent
                textArea.Width = textArea.Width * Me.DataGridView1.Rows(e.RowIndex).Cells(2).Value
                backbrush = New LinearGradientBrush(
              rowBounds.Location, New Point(textArea.Right, textArea.Bottom),
                Color.Red, Color.Blue)
                e.Graphics.FillRectangle(backbrush, textArea)
     
                'Dessine le  contenu ou valeur de  DurationPercent
                e.Graphics.DrawString(text, e.InheritedRowStyle.Font, forebrush,
                    textArea)
     
     
                e.Graphics.SetClip(oldClip)
     
            Finally
                forebrush.Dispose()
                backbrush.dispose()
            End Try
     
            If Me.DataGridView1.CurrentCellAddress.Y = e.RowIndex Then
                ' Paint the focus rectangle.
                e.DrawFocus(rowBounds, True)
            End If
     
        End Sub
        Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
            For j As Integer = 0 To l.Count - 1
                Dim p As Person = l(j)
                p.ChoiceDate = DateTimePicker1.Value
            Next
            RefreshBind()
        End Sub
    End Class
    En espérant qu'il réponde au souci....
    bon code...

  12. #12
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Salut,

    J'ai pris cette exemple et mis dans un nouveau projet afin que je puisse bien l'étudier et voir comment le transposer dans mon code.
    J'ai juste un soucis avec le DTP :
    Erreur 2 'Value' n'est pas un membre de 'System.Windows.Forms.Timer'.
    Erreur 1 L'événement 'ValueChanged' est introuvable.
    J'ai regardé à droite dans les propriétés du timer et je n'est pas ce genre de réglages ..

  13. #13
    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
    RE

    Le DTP, n'est pas un control Timer , mais c'est l'acronyme du control DateTimePicker , communément appelé control calendrier ...
    Qu'on se le dise !!!
    Et que ceux qui ont compris, l'expliquent à ceux qui n'ont pas compris(le facétieux Djoha arabe !!!)...
    bon code ...

  14. #14
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Re MABROUKI,

    Je sais pas pourquoi j'étais parti sur un compteur ..... . Peux-tu me dire les pré-requis pour faire fonctionner cette petite application. Car si je la lance telle quelle et que je choisi une date, çà lève une exception Nullreferenceexception ici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    For j As Integer = 0 To l.Count - 1
    Désolé pour mon faible voir très faible niveau de vbnet

    Pour info, je construits mon datagridview vierge sur 24h00 (colonnes) puis en ligne les 5 salles dans cet exemple (En voyant le code, tu comprendras mon niveau ....):
    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
    'ajout colonnes
            For I = 0 To 23
                If I >= 0 And I <= 9 Then
                    Formgraphique.TableGrapheDataGridView.Columns.Add("Heure", "0" & I & "h")
                Else
                    Formgraphique.TableGrapheDataGridView.Columns.Add("Heure", I & "h")
                End If
                Formgraphique.TableGrapheDataGridView.Columns.Add("Minute", "10")
                Formgraphique.TableGrapheDataGridView.Columns.Add("Minute", "20")
                Formgraphique.TableGrapheDataGridView.Columns.Add("Minute", "30")
                Formgraphique.TableGrapheDataGridView.Columns.Add("Minute", "40")
                Formgraphique.TableGrapheDataGridView.Columns.Add("Minute", "50")
            Next I
            'format colonnes
            For I As Integer = 0 To Formgraphique.TableGrapheDataGridView.ColumnCount - 1
                If Formgraphique.TableGrapheDataGridView.Columns(I).HeaderCell.Value Like "*h" Then
                    'TableGrapheDataGridView.Columns(I).HeaderCell.Style.BackColor = Color.LightGray
                    Formgraphique.TableGrapheDataGridView.Columns(I).HeaderCell.Style.Font = New Font("Arial", 12, FontStyle.Bold)
                End If
            Next I
            For Each _col As DataGridViewColumn In Formgraphique.TableGrapheDataGridView.Columns
                _col.SortMode = DataGridViewColumnSortMode.NotSortable
            Next
     
            'ajout lignes
            Formgraphique.TableGrapheDataGridView.TopLeftHeaderCell.Value = "Salle"
            Formgraphique.TableGrapheDataGridView.Rows.Add()
            Formgraphique.TableGrapheDataGridView.Rows(0).MinimumHeight = 20
            Formgraphique.TableGrapheDataGridView.Rows(0).HeaderCell.Value = "Batiment 1"
            For ZZ As Integer = 0 To Formgraphique.TableGrapheDataGridView.Columns.Count - 1
                Formgraphique.TableGrapheDataGridView.Item(ZZ, 0).Style.BackColor = Color.LightGray
            Next ZZ
            Formgraphique.TableGrapheDataGridView.Rows.Add()
            Formgraphique.TableGrapheDataGridView.Rows(1).MinimumHeight = 30
            Formgraphique.TableGrapheDataGridView.Rows(1).HeaderCell.Value = "1"
            Formgraphique.TableGrapheDataGridView.Rows.Add()
            Formgraphique.TableGrapheDataGridView.Rows(2).MinimumHeight = 30
            Formgraphique.TableGrapheDataGridView.Rows(2).HeaderCell.Value = "2"
            Formgraphique.TableGrapheDataGridView.Rows.Add()
            Formgraphique.TableGrapheDataGridView.Rows(3).MinimumHeight = 30
            Formgraphique.TableGrapheDataGridView.Rows(3).HeaderCell.Value = "3"
            Formgraphique.TableGrapheDataGridView.Rows.Add()
            Formgraphique.TableGrapheDataGridView.Rows(4).MinimumHeight = 30
            Formgraphique.TableGrapheDataGridView.Rows(4).HeaderCell.Value = "4"
            Formgraphique.TableGrapheDataGridView.Rows.Add()
            Formgraphique.TableGrapheDataGridView.Rows(5).MinimumHeight = 30
            Formgraphique.TableGrapheDataGridView.Rows(5).HeaderCell.Value = "5"
            Formgraphique.TableGrapheDataGridView.Rows.Add()
    Ensuite je me connecte à la base access pour récuperer la date de début, de fin, la salle occupée et par qui.
    En fonction de cela je remplis mon datagridview en me positionnant directement dans la bonne colonne en fonction de l'heure et des minutes et je trace mon pseudo trait du style :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    ....
    If Formgraphique.TableGrapheDataGridView.Columns(I).HeaderCell.Value = lheurearrivee & "h" Then
                                                decimalminutearrivee = CDec(laminutearrivee)
                                                If decimalminutearrivee <= 9 Then
                                                    Formgraphique.TableGrapheDataGridView.Rows(XD).Cells(I).Value = laminutearrivee & " " & Convert.ToChar(9668)
                                                    Formgraphique.TableGrapheDataGridView.Rows(XD).Cells(I + 1).Value = nomdepersonne
                                                    For J As Integer = I + 2 To Formgraphique.TableGrapheDataGridView.Columns.Count - 1
                                                        Formgraphique.TableGrapheDataGridView.Rows(XD).Cells(J).Value = Convert.ToChar(9644)
                                                    Next J
                                                end if
    end if
    ....
    Enfin en voyant mon code actuel, c'est une vrai usine chimique ....

  15. #15
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Bonjour à tous,

    Toujours à la chasse d'une solution. J'ai à nouveau regardé l'évènement cellpaint ici :
    https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx

    Malheureusement le résultat n'est pas ce que j'attends. J'ai regardé via l'utilisation de gdiplus.dll en regardant le cours et les exemples de arkham46, mais trop compliqué pour moi...

    Existe-t'il un moyen simple pour remplacer ceci ? :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Formgraphique.TableGrapheDataGridView.Rows(XD).Cells(J).Value = Convert.ToChar(9644)
    Dans cet exemple, cela me fait un trait au milieu de la cellule. Moi je cherche à avoir un trait qui prend toute la largeur de la cellule au milieu et ou je peux éventuellement augmenter l'épaisseur. Un peu comme séparer une cellule en deux par un trait horizontal. J'avais vu ce topic, dont la réponse de @Graffito :
    http://www.developpez.net/forums/d93...w/#post5251976
    Le topic concerne du langage C mais je pense qu'en VB.Net cela est possible ...

    Merci pour votre aide

  16. #16
    Inactif  

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2012
    Messages
    4 904
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2012
    Messages : 4 904
    Points : 10 168
    Points
    10 168
    Billets dans le blog
    36
    À ma connaissance, le seul personnage qui a été diagnostiqué comme étant allergique au mot effort. c'est Gaston Lagaffe.

    Ô Saint Excel, Grand Dieu de l'Inutile.

    Excel n'a jamais été, n'est pas et ne sera jamais un SGBD, c'est pour cela que Excel s'appelle Excel et ne s'appelle pas Access junior.

  17. #17
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Bonjour clementmarcotte,

    Je viens de jeter un oeil aux deux liens. Le premier est un exemple pour dessiner des boutons apparemment dans une cellule.
    Le deuxième lien concernant la classe est trop compliqué pour moi et j'ai du mal à voir ce qui pourrait m'intéresser.

    Moi je veux juste un trait horizontal au milieu ou je peux augmenter l'épaisseur dans une cellule précise Je ne pensais pas que c'était aussi dur que cela ....

  18. #18
    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
    Désolé pour mon faible voir très faible niveau de vbnet
    C'est la ou le bat blesse...!!!
    Déjà le fait de découper les 24 heures à raison de 6 colonnes par heure(tes fameux (0h -10-20-30-40-50) va compliquer la conversion des heures et minutes en abscisse colonne : 2 h 20 => 2*6 +20/10=12+2=14eme colonne...
    J'espère en plus que tu n'as pas des horaires du style :
    - heure d'arrivée : 15 h 23 et heure fin : 16 h 47 parce que ,en plus du fait que de tels employés volent leurs patrons , le service comptable ne se retrouvera pas dans ces calculs d'épiciers !!!!
    La solution qui suit utilise la division entière qui arrondi donc l'abscisse colonne ... Ensuite on utilise la couleur pour dessiner le "rectangle" de Gant + un trait continu (eh oui !!!)...
    L'illusion est parfaite et digne d'un Maffiosi !!! .
    Elle le fait dans l'event CellPainting ou l'on récupère les valeurs des horaires départ et fin ,le nom du "quidam" à partir du DataTable d'exemple....
    Un array auxiliaire de couleurs est associe aux lignes du DGV pour faciliter le "fill" du "rectangle de Gant" ...

    code .vb avec un Form ,2 DGV (le 2eme sert à afficher les données du DataTable) à copier ,générer et exécuter:

    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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
     
     
    Public Class FormGantDGV
        Private maTable As DataTable
        Private ColorColums() As Color
        Private Sub FormGantGridBis_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
            Me.DataGridView1.Dock = DockStyle.Top
            Me.DataGridView2.Dock = DockStyle.Bottom         'ajout colonnes
     
            For I As Integer = 0 To 23
                If I >= 0 And I <= 9 Then
                    Me.DataGridView1.Columns.Add("Heure" + I.ToString(), "0" & I & "h")
                Else
                    Me.DataGridView1.Columns.Add("Heure" + I.ToString(), I & "h")
                End If
                Me.DataGridView1.Columns.Add("Minute10", "10")
                Me.DataGridView1.Columns.Add("Minute20", "20")
                Me.DataGridView1.Columns.Add("Minute30", "30")
                Me.DataGridView1.Columns.Add("Minute40", "40")
                Me.DataGridView1.Columns.Add("Minute50", "50")
            Next I
     
     
            'format colonnes
            For I As Integer = 0 To Me.DataGridView1.ColumnCount - 1
                If Me.DataGridView1.Columns(I).HeaderCell.Value Like "*h" Then
                    'TableGrapheDataGridView.Columns(I).HeaderCell.Style.BackColor = Color.LightGray
                    Me.DataGridView1.Columns(I).HeaderCell.Style.Font = New Font("Arial", 12, FontStyle.Bold)
                End If
            Next I
            For Each _col As DataGridViewColumn In Me.DataGridView1.Columns
                _col.SortMode = DataGridViewColumnSortMode.NotSortable
            Next
     
            'ajout lignes
            Me.DataGridView1.TopLeftHeaderCell.Value = "Salle"
            Me.DataGridView1.Rows.Add()
            Me.DataGridView1.Rows(0).MinimumHeight = 20
            Me.DataGridView1.Rows(0).HeaderCell.Value = "Batiment 1"
            For ZZ As Integer = 0 To Me.DataGridView1.Columns.Count - 1
                Me.DataGridView1.Item(ZZ, 0).Style.BackColor = Color.LightGray
            Next ZZ
            Me.DataGridView1.Rows.Add()
            Me.DataGridView1.Rows(1).MinimumHeight = 30
            Me.DataGridView1.Rows(1).HeaderCell.Value = "1"
            Me.DataGridView1.Rows.Add()
            Me.DataGridView1.Rows(2).MinimumHeight = 30
            Me.DataGridView1.Rows(2).HeaderCell.Value = "2"
            Me.DataGridView1.Rows.Add()
            Me.DataGridView1.Rows(3).MinimumHeight = 30
            Me.DataGridView1.Rows(3).HeaderCell.Value = "3"
            Me.DataGridView1.Rows.Add()
            Me.DataGridView1.Rows(4).MinimumHeight = 30
            Me.DataGridView1.Rows(4).HeaderCell.Value = "4"
            Me.DataGridView1.Rows.Add()
            Me.DataGridView1.Rows(5).MinimumHeight = 30
            Me.DataGridView1.Rows(5).HeaderCell.Value = "5"
     
            'Fill table
            maTable = New DataTable
            FillTable(maTable)
     
            'Fill array de couleurs 
            FillColorColums(DataGridView1)
     
            'Ce 2eme DataGridView sert à afficher les donnees de la table
            DataGridView2.DataSource = maTable
     
        End Sub
        Private rnd As New Random
        Private Sub FillTable(ByVal dt As DataTable)
     
            Dim colNom, colHeureArrivee, colMinuteArrivee, colHeureFin, colMinuteFin As DataColumn
            colNom = New DataColumn("Nom", GetType(String))
            colHeureArrivee = New DataColumn("HeureArrivee", GetType(Integer))
            colMinuteArrivee = New DataColumn("MinuteArrivee", GetType(Integer))
            colHeureFin = New DataColumn("HeureFin", GetType(Integer))
            colMinuteFin = New DataColumn("MinuteFin", GetType(Integer))
     
            dt.Columns.Add(colNom)
            dt.Columns.Add(colHeureArrivee)
            dt.Columns.Add(colMinuteArrivee)
            dt.Columns.Add(colHeureFin)
            dt.Columns.Add(colMinuteFin)
     
            Dim dateArrive As DateTime = Date.Now
            Dim dateFin As DateTime
            Dim heure, minute As Integer
     
            Dim dr As DataRow = dt.NewRow
            For i As Integer = 1 To Me.DataGridView1.Rows.Count - 1
                dr(0) = "Nom" + i.ToString
     
                heure = rnd.Next(6, 23)
                minute = rnd.Next(30, 60)
                dateArrive = dateArrive.AddHours(heure)
                dateArrive = dateArrive.AddMinutes(minute)
     
                heure = rnd.Next(6, 23)
                minute = rnd.Next(30, 60)
                dateFin = dateArrive.AddHours(heure)
                dateFin = dateArrive.AddMinutes(minute)
     
                If dateFin < dateArrive Then
                    Dim temp As Date = dateFin
                    dateFin = dateArrive
                    dateArrive = temp
                End If
     
                dr(1) = dateArrive.Hour
                dr(2) = dateArrive.Minute
                dr(3) = dateFin.Hour
                dr(4) = dateFin.Minute
                dt.Rows.Add(dr)
                dr = dt.NewRow
            Next
     
        End Sub
     
     
        Private Sub FillColorColums(ByVal dgv As DataGridView)
            ColorColums = New Color(dgv.Rows.Count) {}
     
            ColorColums(0) = Color.LightBlue
            ColorColums(1) = Color.LightCoral
            ColorColums(2) = Color.LightGoldenrodYellow
            ColorColums(3) = Color.LightGreen
            ColorColums(4) = Color.LightSalmon
            ColorColums(5) = Color.LemonChiffon
            ColorColums(6) = Color.LightYellow
            ColorColums(7) = Color.LightSkyBlue
     
     
        End Sub
     
     
        Private nomItem As String = String.Empty
        Private myColor1 As Color = Color.Transparent
        Private colDebut, colFin, partieMinute As Integer
        Private Sub DataGridView1_CellPainting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
            If maTable Is Nothing Then Return
            If (e.ColumnIndex >= 0 AndAlso e.RowIndex > 0) Then
     
                Dim newRect As New Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1,
                    e.CellBounds.Width - 4, e.CellBounds.Height - 4)
     
                Dim foreColorBrush As New SolidBrush(e.CellStyle.ForeColor)
                Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor)
                Dim gridBrush As New SolidBrush(Me.DataGridView1.GridColor)
                Dim gridLinePen As New Pen(gridBrush)
                Dim diagramPen As New Pen(Brushes.Red, 2.0)
                Dim NamePrinted As Boolean = False
                Try
     
                    ' Erase the cell.
                    e.Graphics.FillRectangle(backColorBrush, e.CellBounds)
     
                    ' Draw the grid lines (only the right and bottom lines;
                    ' DataGridView takes care of the others).
                    e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
                        e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
                        e.CellBounds.Bottom - 1)
                    e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
                        e.CellBounds.Top, e.CellBounds.Right - 1,
                        e.CellBounds.Bottom)
     
                    'recupere le nom du datable
                    nomItem = maTable.Rows(e.RowIndex - 1).Item(0).ToString()
     
                    'recupere la couleur Background  de ColorColums
                    myColor1 = ColorColums(e.RowIndex)
     
                    'recupere colonne debut apres conversion des heures et minutes
                    'en abscisse colonne 
                    colDebut = maTable.Rows(e.RowIndex - 1).Item(1)
                    colDebut *= 6
                    partieMinute = maTable.Rows(e.RowIndex - 1).Item(2)
                    partieMinute = partieMinute / 10
                    colDebut += partieMinute
     
                    'recupere colonne fin (idem)
                    'en abscisse colonne 
                    colFin = maTable.Rows(e.RowIndex - 1).Item(3)
                    colFin *= 6
                    partieMinute = maTable.Rows(e.RowIndex - 1).Item(4)
                    partieMinute = partieMinute / 10
                    colFin += partieMinute
     
                    If e.ColumnIndex >= colDebut And e.ColumnIndex <= colFin Then  ' dans la plage ? 
     
                        e.CellStyle.BackColor = myColor1
                        backColorBrush.Color = myColor1
     
                        ' Fill  the background cell
                        e.Graphics.FillRectangle(backColorBrush, e.CellBounds)
     
                        ' Draw the text content of the cell (1 seule fois)
                        If e.ColumnIndex = colDebut + 1 Then
                            e.Graphics.DrawString(nomItem, e.CellStyle.Font,
                            foreColorBrush, e.CellBounds.X + 2, e.CellBounds.Y + 2,
                             StringFormat.GenericDefault)
                        End If
     
                        ' Draw the bar diagram
                        Dim p0 As New Point
                        Dim p1 As New Point
                        p0.X = e.CellBounds.Left
                        p0.Y = e.CellBounds.Top + e.CellBounds.Height / 2
     
                        p1.X = e.CellBounds.Right
                        p1.Y = p0.Y
                        e.Graphics.DrawLine(diagramPen, p0, p1)
                    End If
                    e.Handled = True
                Finally
                    gridLinePen.Dispose()
                    gridBrush.Dispose()
                    foreColorBrush.Dispose()
                    backColorBrush.Dispose()
                    diagramPen.Dispose()
                End Try
     
            End If
     
        End Sub
    End Class

    bon code.........

  19. #19
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    261
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2012
    Messages : 261
    Points : 98
    Points
    98
    Par défaut
    Hello,

    Merci pour ton aide.
    J'ai donc crée un form que j'ai appelé : FormGantDGV et j'y ai glissé les deux DGV l'un en dessous de l'autre.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Private Sub FormGantGridBis_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Comme je n'ai qu'un form, ce ne devrait pas être ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Private Sub FormGantDGV_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Quand je le lance tel que, rien ne se passe mes deux DGV sont gris. Il manque certes les données mais un des tableaux ne devrait pas afficher déjà les fuseaux horaires ? (le Datagridview1)

    Quand tu dis Datatable de l'exemple pour le Datagridview2 (celui qui contient les infos), tu parles de quel exemple ?
    C'est juste pour voir la structure de cette BDD.

  20. #20
    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
    Re
    Comme je n'ai qu'un form, ce ne devrait pas être ?
    Exact ,le bis vient d'un renommage que j'ai fait !!!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Private Sub FormGantGrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Ensuite tout s'affiche gris parce il manque ce:
    1/ le code Handles MyBase.Load qui demarre l'execution du code d'exemple donné...
    2/ l'association de l'event Load precedent à ton Form qui se fait comme suit :
    Dans le designer tu pointe sur ton form:
    Proprietes ->Icone Event ->Load et dans le combo tu selectionne la ligne de code qui apparait : FormGantGrid_Load
    Tu generes et executes ....
    bon code...

Discussions similaires

  1. [c#] Remplir un DataGridView avec plusieurs DataTable
    Par macfred dans le forum Windows Forms
    Réponses: 2
    Dernier message: 23/02/2010, 11h02
  2. Réponses: 1
    Dernier message: 28/09/2006, 11h43
  3. Demande de conseil pour réaliser un planning
    Par massol joel dans le forum Access
    Réponses: 6
    Dernier message: 26/08/2006, 12h09
  4. [DBMS_STATS][9i]Réaliser la même opération qu'avec ANALYZE.
    Par Le nain Attila dans le forum Oracle
    Réponses: 7
    Dernier message: 09/06/2006, 18h35
  5. Comment réaliser des modèles de documentations avec XML ?
    Par Dams76 dans le forum XML/XSL et SOAP
    Réponses: 6
    Dernier message: 29/08/2003, 02h15

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