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
| Private Class DGVRubrique
Inherits DataGridViewRow
' Cette classe modifie le comportement du DataGridView si on est sur une ligne de rubrique
Protected Overrides Sub Paint(ByVal graphics As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, _
ByVal rowBounds As System.Drawing.Rectangle, ByVal rowIndex As Integer, _
ByVal rowState As System.Windows.Forms.DataGridViewElementStates, _
ByVal isFirstDisplayedRow As Boolean, ByVal isLastVisibleRow As Boolean)
MyBase.Paint(graphics, clipBounds, rowBounds, rowIndex, rowState, isFirstDisplayedRow, isLastVisibleRow)
' Si la valeur de la 1ère cellule est à -1, c'est que c'est une rubrique !
' On va donc lui passer sa couleur à la couleur vert, et on vire certaines colonnes
If Me.Index > -1 Then
' On n'est pas sur la ligne de header
If Not IsNothing(Me.Cells(0)) AndAlso Me.Cells(8).Value = 1 Then
With leStyle
.BackColor = Principale.STYLEGlobale.couleurFondEntete
.SelectionBackColor = .BackColor
.ForeColor = Principale.STYLEGlobale.couleurPoliceEntete
.SelectionForeColor = .ForeColor
Using uneFont As New Font("Trebuchet MS", 8.25!, System.Drawing.FontStyle.Bold, _
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
.Font = Principale.STYLEGlobale.PoliceEntete
End Using
End With
Me.DefaultCellStyle = leStyle
' Là on modifie la couleur de fond de la ligne entière
Using unBrushPerso As New SolidBrush(Principale.STYLEGlobale.couleurFondEntete)
' Ce rectangle c'est la ligne entière
'Dim rect As Rectangle = Me.DataGridView.GetRowDisplayRectangle(Me.Index, False)
' Rectangle correspondant à la cellule de départ du brush de cette ligne
With Me.DataGridView
Dim rectCelluleLibCode As Rectangle = .GetCellDisplayRectangle(3, Me.Index, False)
' Rectangle correspondant à la dernière cellule de la ligne
Dim rectDernièreCellule As Rectangle = .GetCellDisplayRectangle(Me.DataGridView.Columns.Count - 1, Me.Index, False)
' On fait donc un rectangle de la cellule suivant le libellé, jusqu'à la fin
' Et on lui applique la couleur de fond qui va bien
With rectCelluleLibCode
Dim rect2 As New Rectangle(.X, .Y, rectDernièreCellule.X + rectDernièreCellule.Width _
- .X, .Height)
graphics.FillRectangle(unBrushPerso, rect2)
End With
'on redessine également la 2ème cellule
Dim rectCellulePays As Rectangle = .GetCellDisplayRectangle(1, Me.Index, False)
With rectCellulePays
Dim rect1 As New Rectangle(.X, .Y, .Width, .Height)
graphics.FillRectangle(unBrushPerso, rect1)
End With
End With
End Using
End If
End If
End Sub
End Class |
Partager