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
|
Public Class Form2
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
PersonnelTableAdapter1.Fill(PersonnelDataSet1.Personnel)
End Sub
Private Sub DGV_CellPainting(sender As Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DGV.CellPainting
If Me.DGV.Columns(0).Index = e.ColumnIndex AndAlso e.RowIndex >= DGV.Rows.Count - 1 Then
Dim newRect As New Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, e.CellBounds.Width - 4, e.CellBounds.Height - 4)
Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor)
Dim gridBrush As New SolidBrush(Me.DGV.GridColor)
Dim gridLinePen As New Pen(gridBrush)
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)
' Draw the inset highlight box.
e.Graphics.DrawRectangle(Pens.Blue, newRect)
' Draw the text content of the cell, ignoring alignment.
If (IsDBNull(e.Value)) Then
Dim libelle As String = "Solde :"
e.Graphics.DrawString(libelle, e.CellStyle.Font, Brushes.Crimson,
e.CellBounds.X + 2, e.CellBounds.Y + 2, StringFormat.GenericDefault)
End If
e.Handled = True
Finally
gridLinePen.Dispose()
gridBrush.Dispose()
backColorBrush.Dispose()
End Try
End If
If Me.DGV.Columns(1).Index = e.ColumnIndex AndAlso e.RowIndex >= DGV.Rows.Count - 1 Then
Dim newRect As New Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, e.CellBounds.Width - 4, e.CellBounds.Height - 4)
Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor)
Dim gridBrush As New SolidBrush(Me.DGV.GridColor)
Dim gridLinePen As New Pen(gridBrush)
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)
' Draw the inset highlight box.
e.Graphics.DrawRectangle(Pens.Blue, newRect)
' Draw the text content of the cell, ignoring alignment.
If (IsDBNull(e.Value)) Then
Dim sum As Single = CalcSolde()
e.Graphics.DrawString(sum, e.CellStyle.Font, Brushes.Crimson,
e.CellBounds.X + 2, e.CellBounds.Y + 2, StringFormat.GenericDefault)
End If
e.Handled = True
Finally
gridLinePen.Dispose()
gridBrush.Dispose()
backColorBrush.Dispose()
End Try
End If
End Sub
Private Function CalcSolde()
Dim solde As Single = 0.0
For i As Integer = 0 To DGV.Rows.Count - 2
solde += DGV.Rows(i).Cells(1).Value - DGV.Rows(i).Cells(2).Value
Next
Return solde
End Function
End Class |
Partager